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

Legacy GM [SOLVED] Understanding Alarms?

P

Pablo Reese

Guest
I'm confused as to exactly how these alarms work in gamemaker because they're doing something unusual...
If I use
Code:
obj_switch.alarm[0] = 1;
the alarm sets itself to a value of 2 for some reason. If I set the code as
Code:
obj_switch.alarm[0] = 0;
then the code sets it at 0 but doesn't run the code in obj_switch.alarm[0].

I guess I want to know why it could be doing this? Also, what frame does gamemaker activate the alarm code?
Thanks!
 

sp202

Member
If you set it to 0 it'll count down straight to -1 and turn off, skipping the alarm event. That first line should work fine, how do you know it's being set to 2?
 

Tthecreator

Your Creator!
Also, what frame does gamemaker activate the alarm code?
I don't understand that line, and I can see that there are a few misconceptions in there.
withing a frame, game maker has a list of events it will execute for every object. You were probably asking about that.
I don't know exactly but I'm guessing it's just after the step event.

I can't come up for any explanation for why gm would set your alarm to 2 if you give it 1.
I did a test myself and was not able to reproduce your exact issue.
I just put "alarm[0]=1" in step, and put "draw_text(x,y,alarm[0])" in the draw event. It gave me a value of 1.
Does there happen to be any other code that is related to that specific alarm. Does it happen on all alarms you use?

Now about your second point, whenever your alarm is 0 it should execute and when it's -1 it should be stationary and not counting.
It's weird that it doesn't execute your code. However, I don't know whether setting it to 0 manually will work like that.
It might be just that game maker only checks your alarms RIGHT AFTER it has counted down by a bit.

If the first example does set your alarm to 2, and the second doesn't, then I'm guessing you are using some code in the alarm event that resets the alarm again?
 
the alarm sets itself to a value of 2 for some reason
That by itself is impossible. How are you checking that it sets itself to 2?

Also, what frame does gamemaker activate the alarm code?
Thanks!
alarms trigger on value 0 - Did you check the docs?

There are twelve alarms built into each instance of an object, and each one has its own event that will run when this variable reaches 0. it should be noted that the alarm is not finished at that point (although the event has been triggered) as the next step it will go down to -1, so if you need to stop an alarm for any reason you should set its array value to -1 not 0. Alarm times are calculated in game steps, with a value of 30 being 30 steps etc...

NOTE: An alarm with no actions or code in it will not run. However, even with just a comment and no code, the alarm will count down.
 
P

Pablo Reese

Guest
I think my problem comes from a bit of code that adds 1 to the alarm every frame. I still don't know why this would make alarm[0] = 1 turn into 2 though. Is there any way I can use a function to activate the code in alarm[0] immediately so that I don't have to wait a frame for it to activate?
 
M

Matt Hawkins

Guest
if your code is in the step event you should use something like this.
if obj_switch.alarm[0] = -1
{
obj_switch.alarm[0] = 1;
}
 

FrostyCat

Redemption Seeker
I think my problem comes from a bit of code that adds 1 to the alarm every frame. I still don't know why this would make alarm[0] = 1 turn into 2 though. Is there any way I can use a function to activate the code in alarm[0] immediately so that I don't have to wait a frame for it to activate?
That can be done with event_perform().
Code:
event_perform(ev_alarm, 0);
 
Top