N
NicNamSam
Guest
Hello. I decided that, instead of a bunch of objects accessing the variables of my player object, I would use global variables. This is my first time using them. Unfortunately they do not work like they are supposed to. I have tried setting the variables multiple ways: In an "initialization" dummy object placed in the room that sets the variables first then spawns my player object and other objects after; and I also tried putting it in the creation code for the room itself. I have made sure that the objects calling the variables are created after the variables are already set, but Game Maker throws the error no matter what.
The first global variable that triggers the error is called "g_Weapon" to store what weapon my character is holding. I put "g_" to denote that it's a global variable.
The Game Maker help states "In general you should have a single script or object that declares all your global variables at the very start of the game (for example, in the Room Start Event), so that they are initialised and ready for any instance to use, and this also gives you a handy place to go back and reference should you need to check a variable name." and "Once declared in this way that variable is now considered global and requires no "global." prefix".
I have made sure no other variables are using the names of the global variables. I have put the initializations as early as I possibly can. Here is the error it throws:
It almost looks to me like it's trying to treat g_Weapon as an instance variable when it says "obj_player.g_Weapon", because that's usually how it looks when you access the instance variables of one object from another (objectName.VariableName). If I put "global." before a specific use of "g_weapon", the error just moves to the next use of g_weapon. If I put "global." before every single global object, it finally runs, but that doesn't seem very efficient, and the help explicitly states this shouldn't be necessary.
Can anyone with experience help me with this?
The first global variable that triggers the error is called "g_Weapon" to store what weapon my character is holding. I put "g_" to denote that it's a global variable.
The Game Maker help states "In general you should have a single script or object that declares all your global variables at the very start of the game (for example, in the Room Start Event), so that they are initialised and ready for any instance to use, and this also gives you a handy place to go back and reference should you need to check a variable name." and "Once declared in this way that variable is now considered global and requires no "global." prefix".
I have made sure no other variables are using the names of the global variables. I have put the initializations as early as I possibly can. Here is the error it throws:
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:
Variable obj_player.g_Weapon(100115, -2147483648) not set before reading it.
at gml_Object_obj_player_StepNormalEvent_1 (line 817) - if (g_Weapon == g_Swords || g_Weapon == g_Hook) isWpnHold = true;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_player_StepNormalEvent_1 (line 817)
Can anyone with experience help me with this?