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

Legacy GM Pull up script not working anymore

Z

Zakarul

Guest
i don't know what's wrong with this code.

this is a script that start right after a "ledge grab script" and, in this way, i should be able to pull up my character without having direct control. just like this. https://media.giphy.com/media/l0MYAXkWeyON64x3y/giphy.gifProblem is that this "pull up" script worked perfectly good 3 months ago and now it doesn't. The "only" different thing from 3 months ago is that now i use a different sprite I can even scrap this code and make another but i don't know a different way to make it.

this script works that every frame of the sprite, the character moves up or right/left, for a certain amount of pixels (explained in the first lines of code). My sprite have 30 frames(that's why is so long). In the end, thanks to "state = scr_player_movestate", it should stop and return to the basic script but it doesn't. It just fly away with the animation in loop. i tried to use the "animation end "event but it was useless. thank you!! I am desperate....

the code: this trigger the pull up script from the scr_player_ledgegrab

Code:
if ((key_jump && -key_left) && (place_meeting(x-1,y,obj_wall)))
{
   sprite_index = spr_grabbing_R
    image_xscale = -1;
    state = scr_pull_up;
}     

if ((key_jump && key_right) && (place_meeting(x+1,y,obj_wall)))
{
    sprite_index = spr_grabbing_R
    image_xscale = 1;
    state = scr_pull_up;
}
the scr_pullup script

Code:
//Pull up script

 var height_number = (sprite_height) / (image_number/2)


if ((key_jump && -key_left) && (place_meeting(x-1,y,obj_wall)))
{width_number = ((sprite_width) / (image_number/2)) * -1}
else
if ((key_jump && key_right) && (place_meeting(x+1,y,obj_wall)))
{width_number = ((sprite_width) / (image_number/2))}




if image_index = 0 // one for every frame
{
    y -= height_number
}
if image_index = 1
{
    y -= height_number
}
if image_index = 2
{
    y -= height_number
}
etc... (it was too long to post it here so i made a cut)
if image_index = 14
{
    y -= height_number
}
if image_index = 15
{
    y -= height_number
}
if image_index = 16
{
    x += width_number
}
if image_index = 17
{
    x += width_number
}
etc...
if image_index = 28
{
    x += width_number
}
if image_index = 29
{
    state = scr_player_movestate
}
 

obscene

Member
First: Switch Statements. Learn to use them!
Second: Your script doesn't return a value, so by default it returns a 1. So whatever you meant for state=scr_pull_up to do... what is really happening is you are assigning the value 1 to state over and over and running the script forever.
 
Z

Zakarul

Guest
First: Switch Statements. Learn to use them!
Second: Your script doesn't return a value, so by default it returns a 1. So whatever you meant for state=scr_pull_up to do... what is really happening is you are assigning the value 1 to state over and over and running the script forever.
Thank you! i used the switch statement and now it look so much better but the same problem persist.
Code:
//Pull up script

var height_number = (sprite_height) / (image_number/2)


if ((key_jump && -key_left) && (place_meeting(x-1,y,obj_wall)))
{width_number = ((sprite_width) / (image_number/2)) * -1}
else
if ((key_jump && key_right) && (place_meeting(x+1,y,obj_wall)))
{width_number = ((sprite_width) / (image_number/2))}

switch(image_index)
{
    case 0 :
    case 1 :
    case 2 :
    case 3 :
    case 4 :
    case 5 :
    case 6 :
    case 7 :
    case 8 :
    case 9 :
    case 10 :
    case 11 :
    case 12 :
    case 13 :
    case 14 :
    case 15 :
        y -= height_number
        break;
    case 16 :
    case 17 :
    case 18 :
    case 19 :
    case 20 :
    case 21 :
    case 22 :
    case 23 :
    case 24 :
    case 25 :
    case 26 :
    case 27 :
    case 28 :
        x += width_number;
        break;
    case 29:
        state = scr_player_movestate;
        break;
}

with "state" i mean: "script_extecute(state)"
with this i load every script i need like the one i use to climb ladders

it's like
Code:
if (key_left) && place_meeting(x,y+1,obj_ladder)
{
state = scr_ladder // in this way i enter the new script where i just go up and down the ladder
}
then in the new script

if !place_meeting(x,y, obj_ladder)
{
state = scr_player_movestate //in this way i leave the "old" script and return to the normal/idle one.
}
 
Top