#Grab move isn't working as intended

9 messages · Page 1 of 1 (latest)

vast trench
#

I'm making a 2d platformer and I seem to have problems with making a grab move
this is my code:

function player_grab(){
    grab_time = 20
    state = 5
    if (state == 5) && (grab_time > 0) && (!place_meeting(x + hsp,y,obj_solid))
    {
        sprite_index = spr_player_grab
        hsp = (image_xscale * 8)
        grab_time--
    }
    else if (state == 5) && (grab_time > 0) && (place_meeting(x + hsp,y,obj_solid))
    {
        grab_time--
        sprite_index = spr_player_grabwall
        vsp = -3
    }
    else
    {
        state = last_state
        grab_time = 0
    }
}```
the error is, I made a grab_time variable to limit the duration of the grab, but instead it stays stuck at 19 instead of dropping down to 0 and stop the grab
glass solar
#

are you running this function in your step event?
if so, you need to move the grab_time = 20; state = 5 into some create event, since it'll keep getting reset to 20 at the start of the step, and get 1 subtracted leaving you at 19 every step

vast trench
#

hmm how would that work

#

doesn't the create event only run when the instance is created?

glass solar
#

yes

#

you'll need to reset it after you're finished running

vast trench
glass solar
#

yep