GameMaker Global or local variable?

Vallo92

Member
At the performance level, is it recommended to create and use a global variable, or use a simple local variable of an instance and invoke it from other objects with "objname.variablename"?
Obviously I refer to the interaction of objects with the variable within a single room.
 
N

NeZvers

Guest
I haven't tested, but at the moment I use oController.buttons to get input.
If you are going to use an external variable for a loop then better to make temporary var and assign the value of the needed variable before loops
 

TsukaYuriko

☄️
Forum Staff
Moderator
If it's not required to be global, don't make it global.

Performance should not be what you're concerned about here. There is a fundamental difference between a solution that's properly implemented and one that's marginally faster but improperly implemented, most of which lies within the maintainability of the code. Introducing performance gain at the cost of maintainability is an easy way to predetermine a project's death.

To answer the actual question, you can test it yourself: http://gmc.yoyogames.com/index.php?showtopic=604444
You might also want to take the tech blog about optimization into consideration: https://help.yoyogames.com/hc/en-us/articles/216754778-Optimizing-Your-Games
 
Performance wise, it has been stated by the devs that global variables are basically just stored in a special instance, so there should be no difference between that and using an instance variable via instance.variable
 
Top