GMS 2 [SOLVED] Error with alarms, plz help

R

Ryan Blaney

Guest
Ok, I'm making an RPG game with a unique battle system. The problem is, the enemy can only do one attack at a time. I have a value called attack, which sets the alarm between the warning animation and the enemy attack animation. I am trying to set the attack equal to false after the alarm is finished so the other attack can happen, but if i do that, the alarm continuously goes up and never decreases. Can anyone think of a fix?

Step Event:

if (attack == true) {
alarm[0] = atkdel;
attack = false;
}

Alarm[0] Event:

instance_create_depth(xwarn, ywarn, 0, warntype);
show_debug_message("Worked");
audio_play_sound(wasound, 0, false);

if (instance_exists(obj_player) && obj_player.CurrentTile == warntile) {
if (!invincibility) {
obj_player.hp -= enemyStrength;
obj_battle_layout.alarm[1] = invincibilitySpeed;
invincibility = true;
if (obj_player.hp <= 0) {
obj_player.hp = 0;
playerDead = true;
}
}
}

warntype.alarm[0] = atkspd;
 

chamaeleon

Member
If you want attack to be set to false when the alarm goes off (after atkdel steps), set it to false in the alarm event. Just because you set the alarm timer to a value doesn't mean the code right after that assignment waits to execute until the alarm goes off. It will run right away.
 
R

Ryan Blaney

Guest
If you want attack to be set to false when the alarm goes off (after atkdel steps), set it to false in the alarm event. Just because you set the alarm timer to a value doesn't mean the code right after that assignment waits to execute until the alarm goes off. It will run right away.
I'm aware. But the thing you dont understand is that if it is in the alarm event, the alarm gets set to 30 every frame and will NEVER go off.
 

chamaeleon

Member
I'm aware. But the thing you dont understand is that if it is in the alarm event, the alarm gets set to 30 every frame and will NEVER go off.
I was replying to "I am trying to set the attack equal to false after the alarm is finished". I assumed you meant set it to false after the amount of time had elapsed when you phrased it like that. Rereading, perhaps you meant something else. Anyway.. The code as posted will prevent the first alarm from being continuously set off, and will only start another countdown once you set attack to true in some code you haven't shown.
 
R

Ryan Blaney

Guest
I was replying to "I am trying to set the attack equal to false after the alarm is finished". I assumed you meant set it to false after the amount of time had elapsed when you phrased it like that. Rereading, perhaps you meant something else. Anyway.. The code as posted will prevent the first alarm from being continuously set off, and will only start another countdown once you set attack to true in some code you haven't shown.
Don't worry about it. I fixed the problem.
 
Top