error: global variable not set before reading it.

J

jana

Guest
The global variable that is not set before reading is declared in a persistent object that I place in the room (I only have one room right now). It's declared in the game start event. (I tried the room start event and got the same error.)
Code:
global.orb_speed = 5;
This persistent object is the first object on the resource list.
In the room, I checked the instance order and made sure this object is first (I don't know if it matters.).

The code from the object using the variable in its create event:
Code:
motion_set(random(360),global.orb_speed);
The error:
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_orb:

global variable <unknown built-in variable>(-1610512735, -2147483648) not set before reading it.
at gml_Object_obj_orb_CreateEvent_1 (line 4) - motion_set(random(360),global.orb_speed);
############################################################################################
What else can I try?
 

Bingdom

Googledom
The game start event occurs after the create event, also the game start event only triggers if the object existed on the first step of the game.

Quote from manual
Game Start Event
This special event is triggered only once in the whole game and only for those instances with actions or code placed in the event. These instances must be present in the first room of the game and have been placed there in the room editor, rather than have been created dynamically. It should be noted that this event happens after the create event of all instances and so can contain code or actions with variables that have been previously defined in that event. This event is typically defined in only one "controller" object and is typically used to initialize global variables, start music, read from files and any other thing that is usually only done once at the start of a game.
 
W

Wraithious

Guest
You can try having the first object in the room that declairs the global variable then create object obj_orb, in this order:
Code:
//Create even of the  first run object in the first room
global.orb_speed=5;
Instance_create(x,y,obj_orb);
 
J

jana

Guest
The game start event occurs after the create event, also the game start event only triggers if the object existed on the first step of the game.

Quote from manual
That sounds like it could be it.
 
J

jana

Guest
You can try having the first object in the room that declairs the global variable then create object obj_orb, in this order:
Code:
//Create even of the  first run object in the first room
global.orb_speed=5;
Instance_create(x,y,obj_orb);
I think I might have to do something like that.
 

Fabseven

Member
Or you just have to declare aller your global in a single object which IS created first in the room. (There IS à button in the editor to change object order)
 

RangerX

Member
Your problem is only and exclusively related to the order in which the engine reads the events.

- Create events happens first (and your object tries to look at a variable...)
- GameStart comes after ( .... that is declared right here and after)

Since the global variable doesn't exist at the moment the object's create event is read, the engine tells you it couldn't find it.
 
L

lol

Guest
I'm also getting a global var error:


___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object object_11:

global variable name 'mystery_man_text_box_appear' index (100000) not set before reading it.
at gml_Object_object_11_Step_0 (line 7) - if(global.mystery_man_text_box_appear = true){
############################################################################################
 
L

lol

Guest
here's my code=
in one of the objects:
global.mystery_man_text_box_appear = true;
in the other object:
if(global.mystery_man_text_box_appear = true){
visible = true;
}
 
W

Wuzzems

Guest
try putting the global.mystery_man_text_box_appear variable in the create event and change the = at
Code:
if(global.mystery_man_text_box_appear = true)
to double ==, that way it checks for it instead of setting it.

Also try to make sure that there aren't any spelling mistakes
 
Top