• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Wait X second before change room

M

MIkadini

Guest
I want to change room when my character die (i know i must use room_goto(roomName)), but before it i want to wait X second. I try with a while loop that stop code and use the current_time variable and the difference between it and a bigger variable. But this method block all the game. Ther's a way to wait x second before star a function / part of code. Without stop all the game?
 

FoxyOfJungle

Kazan Games
You can simply create a "time" variable, and in the Step Event increase this, if this variable is larger than a number, go to a room using room_goto():
GML:
time += 1;
if (time >= 60)
{
    room_goto(rm_level);
}

60 = 1 second in the game (if your game speed is 60)
You can use this way to get game seconds:
GML:
game_get_speed(gamespeed_fps) * 3 //= 3 seconds (GMS 2)
room_speed * 3 //= 3 seconds (GMS 1.4)
 
Last edited:
M

MIkadini

Guest
You can simply create a "time" variable, and in the Step Event increase this, if this variable is larger than a number, go to a room using room_goto():
GML:
time += 1;
if (time >= 60)
{
    room_goto(rm_level);
}

60 = 1 second in the game (if your game speed is 60)
You can use this way to get game seconds:
GML:
game_get_speed(gamespeed_fps) * 3 //= 3 seconds (GMS 2)
room_speed * 3 //= 3 seconds (GMS 1.4)
i recive an error, In particular i need to start the death room after the character collide with a specific object. i have create a General Game object that in the create event create the global.death variable and set it to false, in the step event of the same object i create this if:

GML:
if (global.morte) {
    time += 1;
    
    if (time >= 60) {
        room_goto(RmGameOver);
    }
}
ps. Morte in italian means death. i recive this error:

Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object ObjGame:

Variable ObjGame.time(100005, -2147483648) not set before reading it.
 at gml_Object_ObjGame_Step_0 (line 22) -        time += 1;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_ObjGame_Step_0 (line 22)
 

FoxyOfJungle

Kazan Games
___________________________________________ ############################################################################################ FATAL ERROR in action number 1 of Step Event0 for object ObjGame: Variable ObjGame.time(100005, -2147483648) not set before reading it. at gml_Object_ObjGame_Step_0 (line 22) - time += 1; ############################################################################################ -------------------------------------------------------------------------------------------- stack frame is gml_Object_ObjGame_Step_0 (line 22)
You forgot to initialize the variable "time" in the Create Event:
GML:
time = 0;
 
Top