GML [SOLVED] Need help changing player state/script

A

anthropus

Guest
Hello,
For some reason which I cannot understand due to noobness, my player can go from the "movement (andar)" state/script to the "cast magic" state, but cannot go from the "idle" state/script to the "cast magic" state even though they use the same code to switch states/scripts.

So I can move and shoot magic, but if Im idle I cant shoot magic. BUT WHY?!?! Please help its driving me crazy!

In the movement state/script is this code which works fine (and so does all the code for movement and collision work in theis script):
Code:
//make the player cast magic
if (spell_button) {current_state=celes_state.cast_magic}
in the idle script the code indicated does not work (even though the rest of the idle state/script code works:
Code:
//idle state
//idle state

//make the player cast magic
//THIS CODE DOESNT WORK
if (spell_button) {current_state=celes_state.cast_magic}

//control player's idle sprite and facing direction

if (currently_facing==facing.upward)
{
sprite_index=sp_celes_walk_up;
image_index=1;
currently_facing=facing.upward;
}

if (hspd=+0 && vspd==0 && currently_facing==facing.downward)
{
sprite_index=sp_celes_walk_down;
image_index=1;
currently_facing=facing.downward;
}

if (hspd=+0 && vspd==0 && currently_facing==facing.leftward)
{
sprite_index=sp_celes_walk_left;
image_index=1;
currently_facing=facing.leftward;
}

if (hspd=+0 && vspd==0 && currently_facing==facing.rightward)
{
sprite_index=sp_celes_walk_right;
image_index=1;
currently_facing=facing.rightward;
}

if (up || down || left || right)
{
current_state=celes_state.andar;
}
and this is "cast magic" state/script:
Code:
//casting magic DOWN state
spd=0

switch (currently_facing)
{
    case facing.upward:
    sprite_index=sp_celes_cast_magic_up;
    instance_create(o_celes.x, o_celes.y-16, o_lrl_up);
    break;
 
    case facing.downward:
    sprite_index=sp_celes_cast_magic_down;
    instance_create(o_celes.x, o_celes.y, o_lrl_down);
    depth=-10;
    break;
 
    case facing.leftward:
    sprite_index=sp_celes_cast_magic_left;
    instance_create(o_celes.x, o_celes.y, o_lrl_left);
    break;

    case facing.rightward:
    sprite_index=sp_celes_cast_magic_right;
    instance_create(o_celes.x, o_celes.y, o_lrl_right);
    break;
}

current_state=celes_state.idle;
thanks
 
Last edited by a moderator:
A

anthropus

Guest
thanks, i tried this and it didnt work. i was able to solve the problem though. what had happened was that in my switch statement which controlled the players states i was skipping a "break;" so one of the states was being skipped. lol i know, im so noob haha
 
Top