GML Macro vs Variables for 1 Instance Uses - GMS2


Daniel Cook

Hey everyone,
I have a quick quiestion about the use of Macro/Constances within entites. I was always told that if you know a variables will not change you should make it constant, stop it being changed by accident & allows programs to alocate apropriate memory space for them.

I have read in the manual that making global variables calls is more resource intencive then local variable calls. I am assuming that this would include Macros and not just (global.Variable) variables.

So lets say I have a back ground sprite for my GUI element. Dependent on some factors I wanted to set the image blend colour of that sprite. The 3 different posisble values would always be the same, but will only be used by this one instance. So is making a macro for this worth it, or am I just wasting resources.

I have tried doing my own test for this by running a game with 50,000 variables & another with 50,000 macros. I then watched the Resource Monitor for results, but they were all over the place. So maybe I don't quite know how to properly extract data from Resource Monitor.

Thanks for reading.

Simon Gust

Macros and enums are being replaced by their corresponding values on compile. So if you had these macros:
CAT = 0
DOG = 1

and wrote code like this
animals[CAT, 0] = random(4);
animals[DOG, 0] = random(7);
animals[MOUSE, 0] = random(2);
animals[HORSE, 0] = random(11);
then on compile, the code would look like this
animals[0, 0] = random(4);
animals[1, 0] = random(7);
animals[2, 0] = random(2);
animals[3, 0] = random(11);
And it would be ultimately faster than any variable, may it be global, instance or temporary.

You really should NOT worry about memory with single variables. If you do, you're not going to have a fun time coding.