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

Animations are not Playing in Order Directed

I have this enemy object in which when after his health is depleted, he will recoil back and then hit the ground. I got the code to work somewhat to a certain extent. For some reason, his death animation will play before the hit sprite and sometimes the hit sprite will play before the death. I need his hit sprite to play before his death all the time.

GML:
    //Enemy Dead
    
    if ( hp <= 0)
    {
    if dead = false
        {
        vsp = -4
        hsp = 3
        obj_player.meter += 25
        dead = true
        state = enemy.hit
        sprite_index = spr_grunthit
        }
        
    if place_meeting(x,y+1,obj_wall)
    {
        hsp = 0
        sprite_index = spr_gruntdead
        image_speed = 1
        state = enemy.dead
    }
    }
 

Umaro

Member
This is all happening in the same frame, so when the second if statement is true, the dead animation will always play regardless of what happened on the first if.
 
Whenever I change states in a state machine, I tend to use the keyword exit immediately after I've done whatever I need to do for the state change to work properly. This quits out of the current event and doesn't let any of the rest of the code execute. The rest of your code executing is probably your problem, as @Umaro pointed out, so this might fix it.
 
Whenever I change states in a state machine, I tend to use the keyword exit immediately after I've done whatever I need to do for the state change to work properly. This quits out of the current event and doesn't let any of the rest of the code execute. The rest of your code executing is probably your problem, as @Umaro pointed out, so this might fix it.

Oh ok, how would i use exit for the code I have written above. Would I need to write it twice or would I use it after the dead state?
 
Top