Waiting in GameMaker: Studio

Sandwall picture Sandwall · May 27, 2016 · Viewed 10.8k times · Source

I composed a script in GML that is supposed to wait a few seconds before executing a script, but I tried it out, and it isn't working. Can someone help? And I don't want to use the wait/sleep function, since that delays everything in the room. Here my script is.

//Rename this script according to what you want to wait for
//Here is how many seconds we want to wait.
var seconds = 0;
//We will multiply the amount of seconds by the room speed, and store it in a variable
var waittime = seconds * room_speed;
//Then, we will define a script for later
var script = "Your Script here";
//Then, we will add a question, and it will ask if the room speed is the same as the wait time
if (room_speed == waittime or room_speed > waittime) {
    //Then, if the amount of room speed is the same as the wait time, then execute the script
    script_execute(script);
}
else {
    //But if the amount of seconds is not equal, or greater than the wait time, then just add the fps to the wait time-
    waittime += fps;
}

Answer

Matey Glishev picture Matey Glishev · May 30, 2016

The sleep function has been removed from GameMaker: Studio as far as I know. You can make your own timer script by using alarms:

In your trigger/pause script:

instance_deactivate_all(true);
alarm[0] = 60 //Your time in frames. If your room_speed is 60, this will be one second.

Then in the Alarm 0 Event you can do something like:

instance_reactivate_all();

Although this will stop rendering any objects you may currently have on screen. Your other bet is to make a global.timer = 60 and stop the step event of every object if(global.timer > 0) and then have something like a director object to run if(global.timer > 0) global.timer--;

Sadly there is no easy way of doing this any more, but hopefully these two methods will suffice.