GameMaker: Studio

GameMaker: Studio

View Stats:
How do I Make a Script run Just Once?
Sorry if this is a newb question. I am trying to make a script run once, then stop. It uses draw commands, so I included it as an object that is created when you enter a certain room. Please help.
< >
Showing 1-2 of 2 comments
The Winter Bud Jun 14, 2018 @ 3:28pm 
gamemaker utilizes 2 types of events.. Continuous and Single. Events like any of the step events or draw events and the keyboard event (when the key is down) happen continuous every step. If you called a script from one of these events, it would be called every step. However, all of the other events happen once when their condition is met. IE.. create event happens when an object is created. keyboard pressed event happens when the correct key is pressed.

You can also use a variable 'flag' to make something happen once
Example
// create event init=true; // flag used to initialize just once // step event if(init==true){ init=false; // initialize data here }

EDIT:
anything that uses draw commands usually goes in a draw event because gamemaker doesn't draw in any other event (except when using surface.. but that's another matter all together.) And any thing drawn needs to be drawn every step or it will not be seen at all. (well unless it blinks or something like that but then again I digress...)
Last edited by The Winter Bud; Jun 14, 2018 @ 3:51pm
RidiculousName Jun 14, 2018 @ 4:11pm 
Originally posted by The Winter Bud:
gamemaker utilizes 2 types of events.. Continuous and Single. Events like any of the step events or draw events and the keyboard event happen continuous every step. If you called a script from one of these events, it would be called every step. However, all of the other events happen once when their condition is met. IE.. create event happens when an object is created. keyboard pressed event happens when the correct key is pressed.

You can also use a variable 'flag' to make something happen once
Example
// create event init=true; // flag used to initialize just once // step event if(init==true){ init=false; // initialize data here }

EDIT:
anything that uses draw commands usually goes in a draw event because gamemaker doesn't draw in any other event (except when using surface.. but that's another matter all together.) And any thing drawn needs to be drawn every step or it will not be seen at all. (well unless it blinks or something like that but then again I digress...)

Thanks, you helped me figure it out! I had been making the array I was using as a guide as part of the draw event, which caused what I was drawing to flicker between different colors according to the values in the array.
< >
Showing 1-2 of 2 comments
Per page: 1530 50

Date Posted: Jun 14, 2018 @ 1:58pm
Posts: 2