Legacy GM Action-Platformer object state bug

R

Remy Savary

Guest
Hi everyone,

I discovered GMS a couple of days ago and followed some tutorials. I took elements from the Shaun Spalding Basic Platformer Tutorial and HeartBeast Basic RPG.

On part 10 of the RPG tutorial at 16min (
) it is shown that once you enter the attack state, the object is stuck in this state. You have to add an "animation end" event to the object with the following code to go back to move state.

///Change Back to Move State
if (state == scr_attack_state){
state = scr_move_state;
}

Here is my problem, if my obj_player does not have an "animation end" event, then he stays in attack state forever once you press X has it should by the tutorial (the M key will force him back to move state), but if the obj_player has an "animation end" event, whether there is a piece of code attached to it or not, the X key does not seem to work anymore and obj_player stays in move state and never enter attack state (or so it seems to me).

Here is my file (there is no animation end event in this one):
http://www.filedropper.com/platformer1gmx_1

Space to jump (double jump if you get the power up on topleft corner of the room)
X to attack (you will be stuck in attack state until you press M) DOES NOT DAMAGE ENEMIES for now
M to force back to move state (does not end the attack animation but you can move the obj_player)
http://www.filedropper.com/platformer1gmx
Anyone understand why the "animation end" event break this game?
 
R

Remy Savary

Guest
scr_move_state
///scr_move_state
scr_get_input();

//reacts to inputs
move = left_key + right_key;
hsp = move * movespeed;

//attack

if(attack_key){
//image_index = 0;
state = scr_attack_state;
}

//gravity
if(vsp < 10){
vsp += grav;
}

if(place_meeting(x,y+1,obj_wall)){
doublejump = true;
vsp = jump_key * -jumpspeed;

} else if (airjump > 0 && !place_meeting(x,y+1,obj_wall)){

if(jump_key && vsp > 0 && doublejump == true){
vsp = jump_key * -jumpspeed;
doublejump = false;
}

}

//horizontal collision
if (place_meeting(x+hsp,y,obj_wall)){

while(!place_meeting(x+sign(hsp),y,obj_wall)){

x += sign(hsp);
}
hsp = 0;
}

//vertical collision
if (place_meeting(x,y+vsp,obj_wall)){

while(!place_meeting(x,y+sign(vsp),obj_wall)){

y += sign(vsp);
}
vsp = 0;
}

//change sprite according to direction
if(hsp > 0){
sprite_index = spr_player_right;
} else if (hsp < 0){
sprite_index = spr_player_left;
}
x += hsp;
y += vsp;

scr_attack_state
///scr_attack_state
image_speed = .5;

switch(sprite_index){
case spr_player_left:
sprite_index = spr_player_atk_left;
break;

case spr_player_right:
sprite_index = spr_player_atk_right;
break;
}

Step event of the obj_player
script_execute(state);

animation end event of the obj_player
///change back to move state

if (state == scr_attack_state){
state = scr_move_state;
}
 
Top