[SOLVED] global not set before read

J

jana

Guest
I have a menu with a play button object. The left mouse event has the following code:
Code:
room_goto(rm_Level1);
When I click, I get this error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of <Unknown Event>
for object obj_counter:

global variable <unknown built-in variable>(-1610512719, -2147483648) not set before reading it.
at gml_Room_rm_Level1_Create (line 9) - global.step_counter_lo = global.steps_until_lo_release;
############################################################################################
obj_counter is an object physically placed in the room.

I do not get this error if I place rm_Level1 at the top of the objects list and run it first.

So, what could be the reason that the global variables are not seen if I run rm_Level1 from the menu page?
 

Weird Dragon

Wizard
GMC Elder
I have a menu with a play button object. The left mouse event has the following code:
Code:
room_goto(rm_Level1);
When I click, I get this error:


obj_counter is an object physically placed in the room.

I do not get this error if I place rm_Level1 at the top of the objects list and run it first.

So, what could be the reason that the global variables are not seen if I run rm_Level1 from the menu page?
That is the kind of error you can get when you run a code in the room creation code of a room in which case there is no event thus the message says "of <Unknown Event>". The message refers to an object, in this case "obj_counter" although the code is not in the object but actually in the room creation code.

This part of the error message:
"at gml_Room_rm_Level1_Create (line 9) - global.step_counter_lo = global.steps_until_lo_release;"
indicates that the code exists in the room creation code in the room "rm_Level1", this code:
Code:
global.step_counter_lo = global.steps_until_lo_release;
Is that correct?

What do you mean with this sentence:
I do not get this error if I place rm_Level1 at the top of the objects list and run it first.
???
 

TheouAegis

Member
It's saying global.steps_until_lo_release wasn't properly declared yet. When is global.steps_until_lo_release declared?

***

What do you mean with this sentence:
???
He's saying the error doesn't occur if he changes the resource order so that rm_Level1 is run first. ...Which seems odd. I'd expect the error to occur if and only if rm_Level1 was at the top.
 
Last edited by a moderator:

Weird Dragon

Wizard
GMC Elder
He's saying the error doesn't occur if he changes the resource order so that rm_Level1 is run first. ...Which seems odd. I'd expect the error to occur if and only if rm_Level1 was at the top.
So would I.

By the way, this part of the error message I can not understand:
"global variable <unknown built-in variable>(-1610512719, -2147483648) not set before reading it."
The idea that there could be an unknown built-in variable is strange. Anyway, errors in room creation codes often give strange error messages.
 
J

jana

Guest
It's saying global.steps_until_lo_release wasn't properly declared yet. When is global.steps_until_lo_release declared?

***



He's saying the error doesn't occur if he changes the resource order so that rm_Level1 is run first. ...Which seems odd. I'd expect the error to occur if and only if rm_Level1 was at the top.
Yes, that's what's happening.

***

Both of the variables in this statement
Code:
global.step_counter_lo = global.steps_until_lo_release;
Are in an object called globals_constants, in the create event, and it's at the top of the objects resource list.
Wouldn't all of that code be visible to any room? Isn't that what global means?

***

I double-checked and both of these are assigned values in the create event of globals_constants.
 
Last edited by a moderator:
M

Mishtiff

Guest
Is it possible that you are accidentally creating the other objects before the global object is instantiated? Have you checked the order in which the objects are created on room load?

place a text and check for instance_exists(obj_counter);
I suspect this is an issue with order of object creation, or possible the object is being removed because it is off screen bounds
 
J

jana

Guest
I actually got it running with the rooms in correct order - splash, menu, Level1. But the action isn't correct. I have have text on the screen counting objects, for debugging purposes, and the values displayed are very strange. I agree that it could be an issue with the order things are created.

When does game start happen? Is that before or after the the first room (in this case splash) is created? Is an object's create code before or after room start code?

***

Ok, it works now. I moved all the room creation code to objects, so I guess the problem had something to do with that. I had written a lot of code for the first level without having a splash screen or menu, so it's hard to know what was wrong.

At any rate, I'll avoid writing room creation code unless it's really minor. Thanks everybody.
 
Last edited by a moderator:

TheouAegis

Member
Instances run create events, room runs creation code, instances run room start events, gm checks if room is first in the game and runs game start events.
 
Top