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

Windows Problem with Ladder State Machine

S

Sub Aqua

Guest
Hi i'm making a platformer/metroidvania and I'm new to Game Maker Studio 2. I'm having difficulty getting a ladder state machine script to work due to an error. Here's my code:
scr_getinputs();
hsp= 0;
vsp= 4* (key_down -key_up)
x = (instance_nearest(x,y,oLadder).x)
if (key_jump) || (!place_meeting(x,y,oLadder))
{
hsp=0;
vsp=0;
state=states.normal
}

scr_collideandmove();


Here is the error:

___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

Variable <unknown_object>.y(1, -2147483648) not set before reading it.
at gml_GlobalScript_scr_player_ladder (line 18) - x = (instance_nearest(x,y,oLadder).x)
############################################################################################
gml_GlobalScript_scr_player_ladder (line 18)


Any help you could give me would be appreciated. My guess is that the script doesn't know what object to use when detecting the closest ladder but I'm not sure.
 
The error message makes sense only if the object calling the script has no "y" property ...which still doesn't make much sense. But GM error messages can be obtuse/wrong at times. Sometimes I will actually have the error on an adjacent line from what it is reporting. This could be what is happening for you, where it's actually objecting to the lines before where "hsp", "vsp", "key_down", and "key_up" is accessed. This is at least a little more possible, since not every object will have those properties (whereas every object should have a "y" property).

Either way, make sure your player is always the object calling the script.

Also, the code will fail if there isn't an oLadder to find (since you are accessing the "x" of the nearest ladder without checking that the call returned noone. Maybe instance deactivation is involved and causing problems? That could be another way the error is occurring.
 
Last edited:
Top