GameMaker Studio - All of the GameMaker Events Explained

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
greetings and welcome my name is aaron craig with let's learn this together stick around to the end for details on how you can win my beginner games course now there are a lot of events inside of game maker studio and to make sure that we're on the same page when you make a new project use game maker language drag and drop is going to look completely different so use game maker language so that it actually looks and functions exactly the same so i've got a project here and i'm just going to create an object because that's where all of the events take place i'm going to make an object and we're going to go through some of these i'm not going to go into detail on all of them because many of them are very similar and there's actually like dozens of events here but there are a few key ones that you need to know how they work the first is the create event this one happens when an object is first created in a room now game maker has rooms by default so if i come in here and i place my object in here now when i run the game that event is going to trigger now there's nothing in here so i'm just going to type show message hello world and now that will come up with a dialog box in our game right there hello world and it only happens one time so create event is wonderful for setting variables and doing things that only need to be triggered once if you want to do something lots and lots of times that is where the step event comes into play but we'll get to that in a second next you have the destroy event now destroy happens when you call the function instance destroy now calling it inside of here won't do much good so i'll actually cut this out of here place it in the create event instance destroy is a really great function which you can specify other objects to destroy or if you don't specify anything it will destroy itself so now as soon as we create it we'll actually destroy it and to check it when it gets destroyed we'll say goodbye world so it gets created and then boom it gets destroyed right away and this is a great place to do things that only need to trigger once such as increasing a player's score if you were doing a game where they're destroying lots of objects that's very helpful too next event is clean up and i'm not really going to touch on cleanup because if you're just learning about events the cleanup event is kind of beyond that scope but essentially it's where you want to clean up all of the data structures that you've created inside of this object or throughout the game but don't worry about that for now let's go on to the step event because the step event is kind of the meat and potatoes of all of the events i personally find myself putting most of my code either in the step event or the draw event depending on which one which kind of object it is so there are three options for the step event these three events are very similar and will probably function exactly the same depending on what you're trying to do so game maker runs 60 times per second and the way it runs its code is it has a begin event which also has a in the draw event you can see here begin to end but in the step event you can set some things to happen before everything else if you really needed to or at the end when it's about to move on to the next frame of your game but we're just going to use the regular step event because that's usually sufficient enough so the step event is going to trigger once every frame which means 60 times a second so i'm going to use the function show debug message this time and i'm just going to put the word running in here now debug messages show up here in the output so if we run this we'll now see this debug message show up except of course if we're actually destroying the object instantly let's comment that out and run it again now we'll see debug message running show up 60 times a second so you can see here that it's getting a lot smaller the game has been paused by moving out of it but it's actually still running and it's making 60 times a second so i'm going to press stop and you can see here that if you wanted to do any sort of input or checking for collisions the step event is where you're actually going to want to do that now there are specific events for those other things let's go and take a look at those and then i'll talk about why you might want to do it in the step event compared to those other events so we're going to skip over a couple of these but now we've got mouse key down key pressed key up and here these events are checking to see if the player is pressing any of the keys that are possible and how they're pressing them so on mouse you have left down which means that is the left mouse button being held down same thing for a key down and then you've got left pressed and this only triggers one time when that button is pressed the first time released is when it's let up and you also have mouse enter and leave and this is great for checking objects that you want to change when a mouse hovers over it those are really great events for those then you also have global events so all of these mouse events are specific to this object like i have to left press on this object but if i wanted to be able to check if the user does any left or right press or middle down this is where you would do it global that will check for all of them and then you have the mouse wheel up and down which i think are pretty self-explanatory and now that you understand kind of how those goes the down pressed and released you can kind of see how the key ones do you've got key down which is when a key is being held down and we can show this by adding an alt and i'll do a show debug message if i can type that is and i'll just put in alt right here and i'll add in a key up on alt saying show message stopped so while i'm holding down the alt key we'll see this debug message when i let up it will disappear so i'm going to press it you can see it's down here and when i stop it stops and now it's no longer typing that debug message so we can see that the key down is when the key is being held down up is when it's released and then pressed is when it's pressed the first time so those are all really useful and you can find specific events for all the keypads digits letters function keys and others back here so you can have specific events for every single key press that you could press on a keyboard with that but you can also do all of that inside the step event and have it be much more controlled inside of here such as saying if keyboard check and then you can have check pressed released or just check and you can say vk alt for the alt key or if you wanted to do a letter key you could do ord a so if we did this show message a now if i press a inside of our game it will bring that message up so inside the step event you actually can do full control over every single key press and everything without having to have specific events here because if your game has too many events it can get a little overwhelming to be able to actually go through them it's not going to slow your game down so if that is the way you want to work then go for it but i find it much easier to just put most of my logic in here and then separate it with regions which is super handy regions allow you to fold code so you can do that and then you know type in a description here like controls and then you just put in all the controls right there and it shows up nice and easy to use all right we skipped over a couple of events the alarm is useful in a lot of different scenarios and what it's used for is to run code after a certain time or just to check how long time has passed so if i add alarm 0 inside of here and in the create event i set alarm 0 you access it like an array like this equals 60. now alarm 0 is going to go from negative 1 which is what the value of it normally is and it will be set to 60. any time an alarm event is not at negative one it's counting down to go back to negative one and at zero it runs the code so show message hi make sure you do double quotes there so if we run this after one second 60 frames this will pop up this is really really powerful because a lot of times you want to run code after a little while something has happened such as if you are changing rooms inside of your game it takes at least one frame to move to that next room so if you need something to trigger on entering a new room but you say change room and then you say alarm 0 equals 1 then that code will trigger when you are actually inside that new room because if you want to access any of the objects inside of the other room you can't without being inside of it so alarms are really helpful there and you can also check to see where an alarm is at so if i say show debug message alarm 0 i can actually check to see where my alarm 0 is at so you can see here it goes all the way down and it counts down and now it's at negative one so that's really really cool so it's at negative one for a long time and it started at 60 but it starts at 59 down there so there you go that's kind of alarms i use them pretty often and they're quite helpful next up is the draw event so draw is similar to the step event and that it runs 60 times a second but the differences is where you can actually draw things on the screen so there are a lot of different events inside of draw the main one that i use is the draw or the draw gui i'm going to have a video specifically breaking down the differences between these two and how you should use them but for now just know that draw is probably what you're going to want to use if you want to put something on the screen and draw gui is what you want to use if it's like an interface so say it's the health bar for the player or you want the map to always be in the left corner top left corner for the player draw gui is the graphical user interface and it is relative to the actual window of the game draw is relative to the room of the game so if our player is over here and we draw something over here that's totally fine but in draw gui if we draw try to draw something over here it'll actually draw right next to the player because that's how it works so in the draw event we can use all the functions like draw well everything we can draw a circle we can draw squares we can draw lines we can draw arrows we can draw a button but if we try to use any of the draw events inside somewhere else like a step event nothing will happen so anytime you want to use draw a draw function it has to be inside of a draw event just so that you know that part's really important and if you use the draw event you need to call draw self if you still want to be able to see your sprite because as soon as you add that draw event you're telling game maker you are taking over i will now handle all of the drawing for this object and if you don't use this function you won't see the sprite so if we just create a new sprite really quickly right here we'll just fill it up and go back to our object without this we will no longer be able to see the object with this we can now see the object in the level there it is so make sure you remember that otherwise you're going to have some problems the rest of the draw events are fairly similar so you've got begin and end for both the guise pre-draw post draw and window resize i'm not going to cover those are very specific and when you actually find out you need those you'll be able to research those because you'll be much further along the last ones are the gesture which are for touch screens now you can simulate some of these the mouse presses kind of simulates gestures as well but they now have a full array of events for gestures if you are making a mobile game which are super helpful but it really helps to be able to actually have a mobile device that you can put this on to make sure these events are working some of them are for things that you really can't do with a mouse like pinching you can only click once on a mouse whereas pinching you need two fingers to be able to do and then we have collision events now this is dedicated to all the other objects you have so the more objects you have the more events that you can have for sp collision specific events this can be really helpful if you're getting a game just up and running really quickly and you have pretty slow moving objects the collision events will just check to see if you're going to collide and it will stop you not allow you to collide with it now there are some downsides to the collision event because if you're moving really fast you actually won't be able to get very close to the object because it will think you're going to collide and it will stop you from colliding before you actually get there there are better ways of doing that and again you can find those on my channel as well then we have other so these ones are actually really helpful they just are categorized as other because there's quite a few different ones you've got outside of room so when an object moves outside of the room that event will trigger this can be really useful because it's actually when the object is completely outside of the room so then you can like destroy the object and no one will actually notice that it's gone because it was already outside of the room and outside of the view because you can't see anything outside of the room you have intersecting boundary which if you touch the boundary of the room that's really useful you can set it to do something specific or like bounce back if you want to do like a you know a bouncing effect so that it always stays inside the room you have views so inside of game maker you create cameras and views and you can check to see if an object is outside of there and then you can maybe stop drawing that object if it's taking a lot of processing power or you can have it move somewhere else like teleport there because we won't be able to see it anymore and so you can do all those things with these events here game start and end room start and end i think are pretty obvious animation end update and animation event these are really really handy because a lot of times you'll have characters or something in your game that's actually animating and if you want to check when something is done such as an object gets blown up then animation end really really helps for that because you can check on the animation end event if it's the end of the explosion sprite and then destroy it so i use that pretty often path ended is specific for paths which i'm going to be making a video on but i'm not going to touch that right now user events is another array of events where you can just set some code in here to trigger on however you want you as the coder actually decide when these events get triggered and that's pretty helpful i use these from time to time you can do anything inside of here and have other objects trigger these as well which can be handy and then we've got a broadcast message which has to do with sequences and that's kind of beyond the scope of this video too asynchronous it means that it will trigger uh just any time that it gets notified so these are things for doing things outside of game maker most of the time but there are also some inside so if you wanted to connect to the internet to a website or get some in-app purchase notification async is what you'll want to use here networking push notification save and load and so on but there are also some of these that are really helpful when you are checking to see uh if something is connected to your system so the async system here it has a lot of properties in the manual which i would encourage you to check that out but this is a really great one for checking if you connect or disconnect controllers such as if you're using an xbox switch or playstation this is where you do that the way you do it is fairly complex but game maker lays it out in the manual really really nicely so check that out if that's some functionality you need and you can also check out my four player split screen tutorial because i actually cover how to use this event inside of their picking up and adding new players as you add them with controllers but that's really all of the events the main ones that you're going to need are the create destroy step alarm and draw you can do full games with just those events because the step event well you can do everything inside of here you can do every other event you can manually take over all of the collisions and key checks the async ones yeah you do need those if you're going to be having some kind of asynchronousity inside of your game but for everything else you can do that alarms you do have to have the alarm event for the alarm to work itself if you set alarm 0 equal to 60 but you don't actually have an alarm event then nothing's going to happen it will never run so that is one thing that yes you do need an alarm event if you need those so i guess alarm create destroy draw and step those are all the ones that i use almost every single time i go into my game or my projects that i'm working on and now i know that was a lot to take in because there are dozens of different events inside of game maker but if you want to dive deeper into that and have it broken down and make a game as we go along check out my website let's learn this together and my beginner course to walk you through creating a top-down shooter where we explore all of those events and more in how to do that in a practical game and just for you if you use the coupon code newbie you'll get 20 off of the course today but if you're someone who prefers a more hands-on physical approach you can also check out my kickstarter where i am writing a book to help you go from zero knowledge of game development to be be able to make your dream game in just 30 days it's almost fully funded and right now is the best time to buy it because it's going to get the best price that you can you can also just support it with just five dollars to get your name in the book if that's something you're interested in but if you want to try your luck at winning the course just leave a comment on this video and in four weeks time i will draw a winner from all of the comments and reach out to you and give you a coupon code for this which you can use at the beginner one if that's where you want to start or you can use it on a discount on any of my other courses as well including the bundle if you wanted to buy it all and just start your game maker journey from beginner and end as an expert and a shout out to all of the awesome people supporting me over on patreon if you want to see your name on the screen or get other perks like joining my discord or one-on-one training with me check it out in the description down below some links are going to be coming up that you might find useful if you want to keep watching from me but as i always say keep making keep learning and i'll talk to you later [Music] you
Info
Channel: Let's Learn This Together
Views: 1,510
Rating: undefined out of 5
Keywords: GameMaker Studio, GameMaker Studio 2, GameMaker Studio Tutorial, GameMaker Studio 2 Tutorial, GMS, GMS 2, GMS Tutorial, GMS 2 Tutorial, LLTT, Let's Learn This Together, GameMaker 2, GameMaker Projects, gms 2.3, GameMaker Studio 2.3, gamemaker studio 2.3 tutorial, beginner tutorial, gamemaker studio 2 events, events explained, create event, destroy event, clean up event, mouse and key events, draw event, the rest, gamemaker studio 2 tips, gamemaker series, learn gamemaker
Id: -qntlnLPwok
Channel Id: undefined
Length: 20min 16sec (1216 seconds)
Published: Fri Oct 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.