since variable_global_exists has been deprecated, and I can't figure out another way to nullcheck a global variable, I'm trying to find a good place to init all my global constants.
I tried setting it in the first room's creation script, but apparently characters' creation code is run before that, so it breaks.
Is there a way to run a script just as the whole thing is being created and before all objects and rooms creation process?
Also, how do we nullcheck variables now without variable_global_exists?
Where to initiate global constants
Started by Dredlockz, Jun 30 2012 06:22 AM
4 replies to this topic
#1
Posted 30 June 2012 - 06:22 AM
#2
Posted 30 June 2012 - 06:37 AM
You can use the new "Game Start" event, which will execute a block of code once only, and before anything else. But you must have it in an object in the first room.
GML does need a NULL value, hopefully when the language is re-factored for GM:Next, that will be implemented.
GML does need a NULL value, hopefully when the language is re-factored for GM:Next, that will be implemented.
#3
Posted 30 June 2012 - 07:44 AM
You can use the new "Game Start" event, which will execute a block of code once only, and before anything else. But you must have it in an object in the first room.
GML does need a NULL value, hopefully when the language is re-factored for GM:Next, that will be implemented.
Thanks for the response.
It didn't work correctly at first. I had ObjectA using a global variable on it's "Create" event.
Then I added an ObjectB that initiated that global variable on it's "Game Start" event.
Apparently, since I added ObjectA to the room first, it's "Create" event triggered before ObjectB's "GameStart" event, which is a bit counterintuitive.
So I changed ObjectA to trigger it's script at "RoomStart" instead of on "Create", then it worked.
Thanks!
#4
Posted 02 July 2012 - 10:23 AM
If they're not arrays, put them in the Constants (menu Resources, bottom-most option). Using constants gives you the extra advantage of being color coded. Things like colors, sizes/distances, indexes, I usually put there.
If you want an array, you can put it in the Game Start event of some object that has one instance in the first room. Usually other stuff within the first room doesn't need many variables, because it is often a title screen of some sort. I usually create a special object for defining such things. If you let that special object create the other instances in the room in its Game Start event after initializing the variables, you can be sure that the special object executes its code before anything else happens. Of course it means the other objects can't use their Game Start events.
If you want an array, you can put it in the Game Start event of some object that has one instance in the first room. Usually other stuff within the first room doesn't need many variables, because it is often a title screen of some sort. I usually create a special object for defining such things. If you let that special object create the other instances in the room in its Game Start event after initializing the variables, you can be sure that the special object executes its code before anything else happens. Of course it means the other objects can't use their Game Start events.
#5
Posted 02 July 2012 - 10:56 AM
The event order is specified clearly in the manual, so you should check that to see exactly how everything is run at startup... I should also mention, that what Erik says above is almost always the best way to go! Most games have a splash screen and a title page and it is rare that any globals will be needed right from the word go, so it's in these instances that you should declare them. if you REALLY need them right from the start of your game, you can also create an empty room that is the same saize as the first "real" room of your game and initialise them there then goto the real game room after.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











