GameMaker Define Empty Macros or Passing Arguments

S

software_antics

Guest
I'm currently starting to develop a game with GMS:2, I come from the old days of GM6-8.1. Before starting my development since I have a heavy C# background I would like to, C#-ify my code-base with some macros. For example, undefined in C#, would translate to null. So, naturally I defined a macro like so:

GML:
#macro null undefined
Easy, right? However, upon further development I realized that it would be nice if I could define some macros that let me better define the scope of variables, something like this:

GML:
#macro local        var
#macro instanced    instance_id[id].
.
However, of course, I cannot set a variable that hasn't be declared so I thought maybe macros could be empty and I could at least maintain the visual appearance:

GML:
#macro local     var
#macro instanced
However, apparently this isn't possible with GML, neither is passing arguments to macros which is also quite depressing. Is there perhaps something else I could do that would give me the results I'm looking for?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Unsure what's not working about about the second part (#macro instanced) - works fine for me:

GML:
#macro instanced
instanced variable = "test";
variable += " test2";
show_debug_message(variable);
-> "test test2".

I have to admit that I'm unsure whether this is intentional, though, as the IDE doesn't seem to handle this properly (it complains that the macro is unused when it quite clearly isn't).
 
S

software_antics

Guest
Unsure what's not working about this - works fine for me:

GML:
#macro instanced
instanced variable = "test";
variable += " test2";
show_debug_message(variable);
-> "test test2".

I have to admit that I'm unsure whether this is intentional, though, as the IDE doesn't seem to handle this properly (it complains that the macro is unused when it quite clearly isn't).
Looks like I've solved it myself:

GML:
#macro local        var
#macro instance        id.
Problem solved and now I can do the following:

GML:
local         foo = "foo";
instanced    bar = "bar";
However, yeah I'm not sure why it doesn't work for me... that's really odd.
 
S

software_antics

Guest
Also, what is the loca keyword actually used for, I can't find any documentation on it at all?
 

TsukaYuriko

☄️
Forum Staff
Moderator
This seems to be the leftovers of what's now an internal-only construct (as using it spawns an error message saying that it's unknown)... it used to have the purpose of differentiating between variables in a scenario where it is unclear which scope a referenced variable is under - like this:

GML:
script:
var test = 0;
with (obj1)
{
    show_debug_message(test); // 0 or 1?
}

obj1 Create:
test = 1;
As far as I recall, local scope always took precedence over instance scope, so in total, it's sort of redundant - if you got yourself into a situation where you had to use it, you had more pressing concerns to take care of.
 
Top