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..
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..