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

[Solved] Error: Variable not set before reading it

Silverfire

Member
Hi all, thanks in advance for the help.

Running GM Studio 1.4, I have obj_waterfall which is an invisible object that creates water objects every few steps.

Instance Creation Code (set in Room window):
Code:
endpoint=416
Create event:
Code:
trigger=0
End Step event:
Code:
trigger+=abs(global.time)
if trigger>6 {alarm[0]=1 trigger=0}
Alarm 0 event:
Code:
with instance_create(x+random(64)-32,y,obj_water) {start=y kill=endpoint}
global.time is a variable that can range between -3 and 3 that can be changed at any time by another object and that affects the rate at which obj_water instances appear, that's why I run an End Step instead of using an alarm that resets itself every few steps.

obj_water code:
End Step event:
Code:
if y>kill or y<start instance_destroy()
vspeed=global.time*8
I get the following error when running the game:
Code:
FATAL ERROR in
action number 1
of Alarm Event for alarm 0
for object obj_waterfall:

Variable obj_water.endpoint(100007, -2147483648) not set before reading it.
 at gml_Object_obj_waterfall_ObjAlarm0_1 (line 1) - with instance_create(x+random(64)-32,y,obj_water) {start=y kill=endpoint}

I'm not sure why I get this error. endpoint is set in the room creation code for obj_waterfall and obj_water is not supposed to have an endpoint variable, but its kill variable should be set to its obj_waterfall spawner's endpoint value no? There will be multiple obj_waterfall instances in a room, so I don't think I can use a global.endpoint variable.
 
Last edited:

jo-thijs

Member
That's a misleading title you've got there.

If I understand correctly what you're trying to do,
you should just simply change your occurences of "endpoint" to "global.endpoint".
You've currently made endpoint a variable local to the room creation code, so it doesn't exist for other instances.
 

Silverfire

Member
Sorry title should be better now. Also, I meant the Instance Creation Code you set in the Room window, not the one in the Settings tab, my bad.
 

Yal

šŸ§ *penguin noises*
GMC Elder
You define endpoint in the waterfall, not the water - so the waterfall has that variable, the water does not, because the water's variable is called kill. So change the code in the water to check for kill instead of endpoint.
 

jo-thijs

Member
Sorry title should be better now. Also, I meant the Instance Creation Code you set in the Room window, not the one in the Settings tab, my bad.
Well, because you use the variable endpoint in a with structure, GameMaker thinks your refering to a variable of obj_water.
You can tell GameMaker that it's actually the variable of the instance that called the with structure by prefixing the "endpoint" with "other." inside the with structure.
 
Top