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

is variable_global_exists() broke or am i misusing it

tylerbertz

Member
if(!variable_global_exists("apple")){
global.apple = 21309734013292217380192417230912837120398123712039;
}

the problem is it returns true regardless if global exists or not
 
Last edited:

FoxyOfJungle

Kazan Games
Apparently it will always return true because you are declaring the variable right away, and it will never be deleted until you close the game.

Out of curiosity, why so many numbers in a variable? This is not supported in GMS 2 and will cause problems.
I think GMS 2 can handle values up to 64 bits. 2^64 (18.446.744.073.709.551.615).
 

FoxyOfJungle

Kazan Games
You cannot delete topics because they may be useful to someone in the future, it is also against the forum rules to delete the content after it is resolved.
 

tylerbertz

Member
actually function() count as global variables that was the problem

I had a function apple(){ // do stuff }

and when i variable_global_exists("apple");
it existed because of that function

[small note]
but the function has to be created in a scrip to be considered global
if created inside a object it is that objects variable
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
To extend the explanation above: That's because scripts run at global scope, so anything declared within them is automatically global, just like how anything declared in an instance scope is automatically instance-scoped.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
variable_global_exists
This is really only useful for checking if there is a global somewhere but you dont know where, what its named and or defined yet
I wouldnt use this to set globals as that could lead to weird behavior depending on were you call it
 

kburkhart84

Firehammer Games
This is really only useful for checking if there is a global somewhere but you dont know where, what its named and or defined yet
I wouldnt use this to set globals as that could lead to weird behavior depending on were you call it
This is a good point. You are better off knowing good and well what has and hasn't been defined, by directly coding it. The only time I need to know something like this is for example to verify if you already initialized my input system. In those specific cases, I just check if an instance of my controller object exists. And even then, it is just debug code I take out if you turn debug mode off.
 
Top