Alarm Problems... [FIXED]

E

Explosive Photons

Guest
MY ALARM ISN'T SETTING OFF!

EXPLANATION:
I have a piece of code in a create event of an object.

global.playerturn = 0;
alarm[0] = 1000;

On the alarm[0] event I have this code:

global.playerturn = 1;

On the press z event I have:
if (global.playerturn = 1) {
effect_create_above(ef_spark,224,128,5,c_red);
}

However, Whenever I press z nothing happens. I have tried waiting for minutes and nothing has happened. I have reloaded the game several times and still nothing. What do I do!?
 

Tornado

Member
Have you been pushing z key only at the beginning or later too? If only on beginning then the code in alarm was not executed yet, so playerturn wasn't 1 yet.

You should not set your alarm like that if you are new to GMS. 1000 means it will trigger after thousand steps. Better use it like this
alarm[0]=room_speed*10;
This means it will trigger after 10 seconds, no matter what your room speed is.

Also you will help yourself a LOT if you start using show_debug_message function.

You can put it anywhere you need it.
For example in alarm
Code:
show_debug_message("alarm 0 triggered. playerturn=" + string(global.playerturn));
Also in z press event
Code:
show_debug_message("z pressed!");
if (global.playerturn == 1) {
    show_debug_message("z pressed and playerturn=1");
    effect_create_above(ef_spark,224,128,5,c_red);
}
You can even just for testing always display the value of alarm. Just put this temporary in step event of the object:
Code:
show_debug_message("alarm0="+string(alarm[0]));
Also it is better practice to use == in "if" instead of = but you don't have too.
 
Last edited:

GMWolf

aka fel666
At 30 fps, 1000 frames is about 30 seconds.
Have you pressed the z key before or after those 30 seconds have elapsed?
(You code suggests you should press it before).
 
E

Explosive Photons

Guest
Thanks for the help guys but I just needed to change the alarm to alarm[0]=room_speed*10. Thanks for taking the time to respond!
 
Top