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

GameMaker State machine not updating

A

AquaticChaos

Guest
I haven't used GMS 2 that much, considering I've just gotten a better laptop to play games and code on (My old computer can't run it), plus I've used GMS 1.4 since 2016. The main issue I'm running into is that, for some odd reason, the Dash state won't return to the Move state after the variable 'dashspd' is less than or equal to 0, which should be continously decreasing. However, neither occurs despite being in the Step event. Here's the entire code.

Code:
/// @description States
scr_Input();

if(event == Move) {
    #region Move
    //Horizontal
    var move = key_right - key_left;
    hsp = move*walkspd;
    if(place_meeting(x + hsp, y, obj_Wall)) {
        while(!place_meeting(x+sign(hsp), y, obj_Wall)) {
            x += sign(hsp);
        }
        hsp = 0;
    }
    x += hsp;

    //Vertical
    vsp += grv;
    if(place_meeting(x, y + 1, obj_Wall) && key_jump) {
            vsp = -10;
    }
    if(place_meeting(x, y + vsp, obj_Wall)) {
        while(!place_meeting(x, y+sign(vsp), obj_Wall)) {
            y += sign(vsp);
        }
        vsp = 0;
    }
    y += vsp;

    //Animation
    if(!place_meeting(x, y+1, obj_Wall)) {
        //Rise or Fall sprite (0 = Rise, 1 = Fall)
        sprite_index = spr_PlayerFall;
        image_speed = 0;
        if(vsp > 0) {image_index = 1;} else if(vsp < 0) {image_index = 0;}
    } else {
        image_speed = 1;
        //Idle sprite, or...
        if(hsp == 0) {sprite_index = spr_PlayerStand;} else {
            //Run sprite
            sprite_index = spr_PlayerRun;
        }
    }
    if(hsp!= 0) {
        image_xscale = sign(hsp);       
    }

    if(key_sword) {event = Attack;}
    else if(key_dash) {event = Dash;}
    #endregion
}
else if(event == Attack) {
    #region Attack

    #endregion
}
else if (event == Dash) {
    #region Dash
    sprite_index = spr_PlayerDash;
    dashspd = 2;
    if(dashspd <= 0) {event = Move;} else {x += image_xscale*walkspd*dashspd; dashspd -= .05;}
    #endregion
}
 

Simon Gust

Member
It's because you're setting dashspd to 2 right there every time.
You should only set dashspd to 2 once and that being in the action you call the dash button.
Code:
else if(key_dash) {
   dashspd = 2;
   event = Dash;
}
 
A

AquaticChaos

Guest
Ah, right. For some odd reason I thought it was about the order code was done in. I'll check it right now and edit an update. Goes to show I haven't used this software in a long time.

EDIT: It does in fact work, thank you very much!
 
Top