• 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!

Help With Alarms?

K

Kyle Bahner

Guest
Having some difficulty w/ alarms while playing around w/ a tutorial in GML. I'm new to Gamemaker and coding and would really appreciate help. Basically I want to use an alarm to create a 1 second delay after reaching a score of 50 in a shooter game before restarting the game. In order to help debug I used draw_text and alarm[0] to display the value of 2 different alarms in the corner of the screen. The game runs at 60 fps.

The first alarm is for spawning enemies, which works perfectly, the code looks like this:
In the Create event of obj_spawner:

alarm[0] = room_speed;

And in the Alarm 0 event of obj_spawner:

instance_create_layer(random(room_width),random(room_height),"EnemyLayer",obj_enemyspawn);
alarm[0] = room_speed;

The second alarm for the 1 second delay, which does not work, looks like this:
In the Create event of obj_game:

thescore = 0;

In the Step event of obj_game:

if (thescore >= 50)
{
alarm[0] = room_speed;
}

In the Alarm 0 of obj_game:

game_restart();

The game runs great and the score is accurately kept and displayed at the top of the screen. Both of the alarm values are displayed on the side. The alarm for the spawner starts at 60, counts down, and spawns 1 enemy every second as intended. The alarm for the game restart delay displays -1 until thescore variable reaches 50. At this point the value switches to 60 but then never counts down and restarts the game. The other alarm continues to run and spawn enemies and the score continues to go up, but the value of the other alarm remains at 60. Why? And how to fix it? Thank you..
 

Cameron

Member
The step event runs every step so it is setting your alarm to equal room_speed every step. It never counts down because its constantly getting reset.
FYI I noticed you posted a duplicate topic in community chat. You only need to post here for this question, no need to double post.
Edit: what you can do is change the code to say:
Code:
if thescore >= 50 and alarm[0] <= -1 {
     alarm[0] = room_speed
}
 
Last edited:
K

Kyle Bahner

Guest
Really!? Now I'm kicking myself. And i realized too late that I posted in the wrong forum the first time. Can't figure out how to take the other one down...
 
Top