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

It says that variable is not defined but it is.

K

kestus0756

Guest
Hello, everyone. I'm back with another problem which is about keybindings. So, the problem is that it says that variable is not defined but it actually is. So, here's the error:
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_key_up:

global variable key_up(100010, -2147483648) not set before reading it.
 at gml_Object_obj_key_up_CreateEvent_1 (line 1) - key = global.key_up;
############################################################################################
I have no idea what's the problem. Any help would be appreciated a lot. (I get a lot of errors because I'm not a professional gamemaker user, only have been using it for like a year, I hope you understand that.)
 
R

Ramaraunt

Guest
What creates the variable initially? Check your instance order. Sorry if you already did, just you didn't give much info.
 

Yal

🐧 *penguin noises*
GMC Elder
You're accessing the variable in the first line of a create event, so I guess you define the global variables in a Game Start event... those are run AFTER create events for some reason, a lot of people get errors about that. I'd personally recommend setting up all global variables in a temporary titlescreen room as early as possible in development so you KNOW they're around, and then have pressing enter go to the actual game.
 
K

kestus0756

Guest
What creates the variable initially? Check your instance order. Sorry if you already did, just you didn't give much info.
Well, I tried putting global.key_up = 0 in Game Start event like Yal said but it doesn't work, still gives the same error.
 

Yal

🐧 *penguin noises*
GMC Elder
The game start event is run after create events. So you can't access anything a Game Start event initializes in the same room.
 
K

kestus0756

Guest
That's actually a pretty good reason. Can't believe I didn't realize that.... It's easy to forget Game Start events are actually run from inside an object, I guess...? x3
I figured a way to fix it, thanks anyways.
 
Top