Legacy GM Sprite Index won't change back after Alarm

D

dawson2223

Guest
I changed my enemies sprite when they were hit with a bullet and set an alarm to reset it, but the alarm portion isn't working. Does anyone know what I forgot in my code?

Create Event:
hit = 0

Collision Event with obj_bullet:
hit = 1;

Step Event:
Code:
/// Enemy Flash when Hit

if (hit = 1 && sprite_index = spr_EnemyRunUp) {
sprite_index = spr_HitUp;
alarm[2] = 10
}
if (hit = 1 && sprite_index = spr_EnemyRunDown) {
sprite_index = spr_HitDown;
alarm[2] = 10;
}
if (hit = 1 && sprite_index = spr_EnemyRunRight) {
sprite_index = spr_HitRight;
alarm[2] = 10;
}
if (hit = 1 && sprite_index = spr_EnemyRunLeft) {
sprite_index = spr_HitLeft;
alarm[2] = 10;
}

if hit=0 {
if sprite_index = spr_HitUp{
sprite_index = spr_EnemyRunUp
}
if sprite_index = spr_HitDown{
sprite_index = spr_EnemyRunDown
}
if sprite_index = spr_HitLeft{
sprite_index = spr_EnemyRunLeft
}
if sprite_index = spr_HitRight{
sprite_index = spr_EnemyRunRight
}
}
Alarm 2:
hit = 0;

----
I've tried putting the second part of the step event in alarm 2 but that didn't work either. Not sure why it isn't resetting. Help Please
 
S

Supercoder

Guest
After a quick look, I'm pretty sure I know the problem. If hit is equal to 1, alarm[2] is being set to 20 every step, meaning it can't run down because it's being continually reset. You could add a check, if alarm[2]==-1, so it only sets the alarm if it's run down.
 
D

dawson2223

Guest
After a quick look, I'm pretty sure I know the problem. If hit is equal to 1, alarm[2] is being set to 20 every step, meaning it can't run down because it's being continually reset. You could add a check, if alarm[2]==-1, so it only sets the alarm if it's run down.
I changed the step event to this instead and it worked but it is only lasting a milisecond, how can I make it longer?
Code:
if alarm[2] == -1 {
if (hit = 1 && sprite_index = spr_EnemyRunUp) {
sprite_index = spr_HitUp;
alarm[2] = 40;
}
if (hit = 1 && sprite_index = spr_EnemyRunDown) {
sprite_index = spr_HitDown;
alarm[2] = 40;
}
if (hit = 1 && sprite_index = spr_EnemyRunRight) {
sprite_index = spr_HitRight;
alarm[2] = 40;
}
if (hit = 1 && sprite_index = spr_EnemyRunLeft) {
sprite_index = spr_HitLeft;
alarm[2] = 40;
}
}

if hit=0 {
if sprite_index = spr_HitUp{
sprite_index = spr_EnemyRunUp
}
if sprite_index = spr_HitDown{
sprite_index = spr_EnemyRunDown
}
if sprite_index = spr_HitLeft{
sprite_index = spr_EnemyRunLeft
}
if sprite_index = spr_HitRight{
sprite_index = spr_EnemyRunRight
}
}
 
S

Supercoder

Guest
Your code seems fine... I assume changing the length of the alarms doesn't do anything? If so, the variable "hit" is probably being changed somewhere else. Can you check?
 
Top