Not working code (alarm_set, alarm_get)

Amigo121

Member
Hello,

I have encountered my very first problem with the code itself. Basically, my code does not work as it should (if you insist "as i want").
Here is my code:

GML:
if (ammo == 0)
{   
    alarm_set(0,120);
    
    if (alarm_get(0) <= 0)
    {
        instance_create_layer(x+50,y-50,"Bullets",oBDuck);
    }
}
I have another condition which lower the ammo every time i shoot. Alarm 0 sets ammo to 3.
Now lets talk about the code above and why it does not work.
"ammo == 0" is real condition (it will eventually happen)
"alarm_set(0,120)" i believe it sets alarm with index 0 for 120 steps
"if (alarm_get(0) <=0)" it checks alarm index 0 value and once the alarm is 0 or lower the condition is true
i am not sure what is wrong with my code but that condition never gets to be true. Any ideas?
 

FrostyCat

Redemption Seeker
You should have taken time off to learn how alarms actually work before using it.
In your Step event code, check that the alarm has not been set before setting it. The alarm in your original code has no hope of going off because you are constantly turning it back to 120. On top of this, the code to run when the alarm elapses DOES NOT BELONG HERE.
GML:
if (ammo == 0 && alarm[0] < 0) {
    alarm[0] = 120;
}
Then go to the event selector, add the Alarm 0 event, and put your instance_create_layer(x+50,y-50,"Bullets",oBDuck); line there.
 

Amigo121

Member
You should have taken time off to learn how alarms actually work before using it.
In your Step event code, check that the alarm has not been set before setting it. The alarm in your original code has no hope of going off because you are constantly turning it back to 120. On top of this, the code to run when the alarm elapses DOES NOT BELONG HERE.
GML:
if (ammo == 0 && alarm[0] < 0) {
    alarm[0] = 120;
}
Then go to the event selector, add the Alarm 0 event, and put your instance_create_layer(x+50,y-50,"Bullets",oBDuck); line there.
Thanks a lot!
 
Top