GameMaker [Solved] Timer for one frame of animation

I made a character that thrusts his sword. He has two frames of animation. A charge (frame 0), and then a stab(frame 1). The charge frame is shown when you hold down the X button on the PS4 controller. The stab is shown when you let go. I want the stab to be displayed longer than just one frame. Once you let go of the button, it stabs but then immediately resets. I want to use a timer to hold the frame out for maybe one second (the game runs at 60fps with image_speed of 1.25 for the player).

Create of player_object
stabClock = 60;

Step Event of player_object
Code:
case STATE_PLAYER.stand:
//  
      if (gamepad_button_check(4, gp_face1)) and (scr_isDpadTouched() == false)
        {
            myState = STATE_PLAYER.stab; //X is pressed so it jumps to case stab
            break;
        } 
//
break;
case STATE_PLAYER.stab:
        scr_playerStab(); //then the script plays
//
break;
scr_playerStab()
Code:
switch (obj_player.facing) //which way the character is facing (up down left right)
{
case 0: //
case 1:
        obj_player.sprite_index = spr_johnB_swordStabRight;
        obj_player.image_index = 0; //this is the charge frame where he's pulling the sword back
        if gamepad_button_check_released(4, gp_face1) 
        {
            while(obj_player.stabClock > 0)
            {
                obj_player.image_index = 1; //thrust frame
                obj_player.stabClock--;
            }
            if (obj_player.stabClock == 0)
            {
                obj_player.stabClock = 60;
                break;
            }
        }
        break;
Currently the timer stays stuck at 60, and he charges properly (frame 0) but still only stabs/thrusts(frame 1) for one frame and then goes back to PLAYER_STATE.stand. None of my states overlap but I do think maybe one issue, other than the broken timer, is that it switches back to PLAYER_STATE.stand before the clock can do anything. This happens because you have to release the button to play the stab, but that also switches states.
 

Slyddar

Member
Break it up. Make a state for the charge, and a state for the stab. That way when they release the button, set a timer at that point, move to the stab state, ensure you count down the timer per step in the stab state, and when the timer has expired, move back to the stand state.
 
Top