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

State Change please help

Hey everyone. So I will be making a game that has 3 inventory slots. When an item is placed in a slot, it will set a variable as true. In addition, there is an item selector that moves between each slot. When you pick up a certain item (the whip), you enter the whip state. If the selector moves away from that slot, then the player re-enters the move state.

The issue seems to be that if the player re-enters the move state while holding a torch (not apart of the item slot system) and then moves the selector back, it never seems to trigger the whip state, leaving the hero in the idle torch sprite, however the sprite freezes.

It's supposed to do this: If the player was holding an unlit torch or a lit torch, it sets a variable to true so that when the player returns to the move state, it checks if the variable is true so that the player gets their torch back.

Here's some code to show how this is done:

Code:
if sprite_index = spr_hero {
    if inventory.whip1 = true && selector.coorleft = true {
        state = whip_state;
    }
    else {
        if inventory.whip2 = true && selector.coorcenter = true {
            state = whip_state;
        }
        else {
            if inventory.whip3 = true && selector.coorright = true {
                state = whip_state;
            }
else {
    if sprite_index = spr_hero_torch_unlit {
        if inventory.whip1 = true && selector.coorleft = true {
            tu = true;
            state = whip_state;
        }
        else {
            if inventory.whip2 = true && selector.coorcenter = true {
                tu = true;
                state = whip_state;
            }
            else {
                if inventory.whip3 = true && selector.coorright = true {
                    tu = true;
                    state = whip_state;
                        }
    else {
        if sprite_index = spr_hero_torch {
            if inventory.whip1 = true && selector.coorleft = true {
            t = true;
            state = whip_state;
        }
        else {
            if inventory.whip2 = true && selector.coorcenter = true {
                t = true;
                state = whip_state;
            }
            else {
                if inventory.whip3 = true && selector.coorright = true {
                    t = true;
                    state = whip_state;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

if t = true && mstate = true {
    sprite_index = spr_hero_torch;
    image_speed = .25;
    image_index = 0;
    mstate = false;
}

if tu = true && mstate = true {
    sprite_index = spr_hero_torch_unlit;
    image_speed = .25;
    image_index = 0;
    tu = false;
    mstate = false;
}

if t = false && tu = false && mstate = true {
    sprite_index = spr_hero;
    image_speed = .25;
    image_index = 0;
    t = false;
    mstate = false;
}
This is how the move state changes to the whip state and, upon being returned to the move state, it checks the variables to determine what sprite they should have and then sets the variable to false in case they lose their torch and then switch to the whip state and back to the move state (don't want to give players free torches :p)

Code:
if (sprite_index != spr_hero_whip_run && sprite_index != spr_hero_whip_swing) {
    sprite_index = spr_hero_whip;
    image_speed = .25;
    image_index = 0;
}

if sprite_index = spr_hero_whip {
    if inventory.whip1 = true && selector.coorleft = false {
        mstate = true;
        state = scr_move_state;
    }
    else {
        if inventory.whip2 = true && selector.coorcenter = false {
            mstate = true;
            state = scr_move_state;
        }
        else {
            if inventory.whip3 = true && selector.coorright = false {
                mstate = true;
                state = scr_move_state;
            }
        }
    }
}
This is how the whip state changes back. If the item selector is not on the whip's inventory slot, it sets the state to the move state. I also added how the whip state changes the sprite to the whip sprite just in case that's the problem, though I believe it has to do with the move state, because you can grab ledges in the move state and you can't in the whip state. Once the sprite freezes (upon moving the selector back to the whip slot while holding a torch), I notice that I can still grab ledges, meaning the state never changed the second time
 
Perhaps so hahaha o_O yeah it's pretty messy code, I was trying to type while talking to someone and listening to something at the same time and it didn't go so well methinks
 
Top