• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Stuck on attack state when inputting the same button multiple times

vsail

Member
Hi, I am quite new with using Gamemaker 2. When I click the left button mouse multiple time, it got stuck on the attack state and not returning to free state. I have been looking anywhere and can not figure it out.
Does anybody know how to fix this issue?

Moving Script
Code:
move_speed = 2;
hsp = 0;
vsp = 0;

if (inputRight){
    if(inputShift){
        image_speed = 2;
        hsp = move_speed * 2;
    } else {
        image_speed = 1;
        hsp = move_speed;
    }
    obj_Player.sprite_index = playerMWalkingRight;
    strDir = "right";
} else if (inputLeft){
    if(inputShift){
        image_speed = 2;
        hsp = -move_speed * 2;
    } else {
        image_speed = 1;
        hsp = -move_speed;
    }
    obj_Player.sprite_index = playerMWalkingLeft;
    strDir = "left";
} else if (inputUp){
    if(inputShift){
        image_speed = 2;
        vsp = -move_speed * 2;
    } else {
        image_speed = 1;
        vsp = -move_speed;
    }
    obj_Player.sprite_index = playerMWalkingBack;
    strDir = "back";
} else if (inputDown){
    if(inputShift){
        image_speed = 2;
        vsp = move_speed * 2;
    } else {
        image_speed = 1;
        vsp = move_speed;
    }
    obj_Player.sprite_index = playerMWalkingFront;
    strDir = "front";
} else if (inputShift){
    image_speed = 0;
    image_index = 0;
} else if (inputNull){
    image_speed = 0;
    image_index = 0;
}

if (inputMouseLeftInput){
    scr_attack()
}

scr_collisionChecker();

show_debug_message("free");

x += hsp;
y += vsp;
Attack Script
Code:
hsp = 0;
vsp = 0;
currentSprite = sprite_index;
currentCollisionMask = mask_index

scr_processAttackAnimation(playerMSlashingFront,playerMSlashingBack,playerMSlashingLeft,playerMSlashingRight,
        0,currentSprite,currentCollisionMask);
        //replace 0 with weapon collision whe ready
        
//Combo active duration
if(inputMouseLeftInput && image_index > 3){
    state = playerStates.combo;
}

if(animation_end()) {
    sprite_index = currentSprite;
    state = playerStates.free;
}

show_debug_message("attack");
Attack animation processor
Code:
currentSprite = argument5;
currentCollisionMask = argument6;

show_debug_message("before switch");

switch(strDir) {
    case "front":
        if(sprite_index != argument0) {
            sprite_index = argument0;
            image_speed = 1;
            image_index = 0;
            ds_list_clear(hitAttack);
            strDir = "front";
        }
        break;
    case "back":
        if(sprite_index != argument1) {
            sprite_index = argument1;
            image_speed = 1;
            image_index = 0;
            ds_list_clear(hitAttack);
            strDir = "back";
        }
        break;
    case "left":
        if(sprite_index != argument2) {
            sprite_index = argument2;
            image_speed = 1;
            image_index = 0;
            ds_list_clear(hitAttack);
            strDir = "left";
        }
        break;
    case "right":
        if(sprite_index != argument3) {
            sprite_index = argument3;
            image_speed = 1;
            image_index = 0;
            ds_list_clear(hitAttack);
            strDir = "right";
        }
        break;
}

show_debug_message("after switch");

mask_index = argument4 //hitbox's mask
hitAttackCurrent = ds_list_create();
hits = instance_place_list(x,y,0,hitAttackCurrent,false)

if(hits > 0) {
    for(var i = 0; i < hits; i++){
        //check instance colision with hitbox mask
        var hitID = ds_list_find_value(hitAttackCurrent, i);
        if(ds_list_find_index(hitAttack,hitID) == -1){
            ds_list_add(hitAttack,hitID);
            with(hitID){
                scr_enemyHit(2);
            }
        }
    }
}
ds_list_destroy(hitAttackCurrent);
mask_index = currentCollisionMask;

show_debug_message("after hitbox checkin");
Combo script
Code:
hsp = 0;
vsp = 0;
currentSprite = sprite_index;
currentCollisionMask = mask_index;

scr_processAttackAnimation(playerMSlashingFront,playerMSlashingBack,playerMSlashingLeft,playerMSlashingRight,
        spr_collider,currentSprite,currentCollisionMask);
        //replace 0 with weapon collision whe ready

//Combo timer
if (inputMouseLeftInput) && (image_index > 3)
{   
    state = playerStates.combo;   
}

if (animation_end())
{
    sprite_index = currentSprite;
    state = playerStates.free;
}

show_debug_message("multi");
Step
Code:
scr_inputs();

switch(state) {
    case(playerStates.free):
        scr_moving();
        break;
    case(playerStates.attack):
        scr_attack();
        break;
    case(playerStates.combo):
        scr_multiAttack();
        break;
}
Global left click
Code:
state = playerStates.attack;
Thank you for your time and any help will be appreciated
 

TheouAegis

Member
Why do you have a Global Left Click event to change the state and a InputMouseLeftInput check in scr_moving()? Make scr_moving() set the state to playerStates.attack and delete the Global Left Click event.
 

vsail

Member
Why do you have a Global Left Click event to change the state and a InputMouseLeftInput check in scr_moving()? Make scr_moving() set the state to playerStates.attack and delete the Global Left Click event.
I have done what you have said, however, the issue still happens.
When I check the debug mode, it shows that animation_end() never returns true so the part where it turns the state = playerState.free never got triggered.
Thank you for your help, though.
 
Last edited:
Top