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

GameMaker Strange Alarm Event Issues

T2008

Member
For some reason, the alarm event will not update a variable to turn true and I have no idea why. After the on sound is played, I want to play a message but beep_on never turns to true. Sometimes in other objects, alarm event works fine. I guess I don't understand how this event works. I've posted the step event code and alarm event code below. Any insight would be greatly appreciated.

Edit: i got it to work using a clock variable; still don't know why alarm doesn't work. Do I have to put alarm[0] = -1 in create event?

Create Event:
Code:
image_speed = 0;

beep_on = false;
beep_sound_played = false;
message_played = false;
sound_on = snd_intercom_beep_on;
sound_message = snd_intercom_last_stop;
beep_clock = 150;
start_message = false;
Step Event:
Code:
//Set Image Index
if (!beep_on) || (message_played) {
    image_index = 0;  
} else {
    image_index = 1;  
}
//Turn On If Player Is Close
if (!beep_on) && (distance_to_object(obj_player) < 50) {
    if (!beep_sound_played) && (!audio_is_playing(sound_on)) {
        audio_play_sound(sound_on,10,false);
        beep_sound_played = true;
    }
}
if (beep_sound_played) {
    //Set Alarm To Update Beep Variable
    alarm[0] = 150;  
}
//Play Message If On And Beep Played
if (beep_on) && (!message_played) {
    if (!audio_is_playing(sound_message)) {
        audio_play_sound(sound_message,10,false);  
    }  
}

if (beep_on) && (!audio_is_playing(sound_message)) {
    message_played = true;
}
Alarm Event:
Code:
beep_on = true;
 
Last edited:

samspade

Member
This code is the problem:

GML:
if (beep_sound_played) {
    //Set Alarm To Update Beep Variable
    alarm[0] = 150; 
}
You are continually setting (or resetting) the alarm to 150 so it can never run down.

Either make beep_sound_played false at some point or only set the alarm if the alarm is unset. You can do this with:

Code:
if (alarm[0] != -1) alarm[0] = 150;
-1 (if I remember correctly) is what alarms are set to when not running.
 
Top