• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 Suggestion: Aliases via macros

So, currently with macros, you can do something like this:

Code:
#macro rnd irandom_range(1, 6)

var res = rnd;

show_message(res);
... But, it would be nice if we were able to do something like this as well:

Code:
#macro rnd irandom_range

var res = rnd(1, 6);

show_message(res);
... Which produces the compile Errors: "cannot use function/script name for a variable, "irandom_range" twice, and "unknown function or script rnd"

Is this possible?
 

gnysek

Member
create new script, name it rnd, and put

Code:
return irandom_range(argument0, argument1);
Works!

Update:

To be 100% valid with your request:
Code:
return irandom_range(argument_count > 0 ? argument[0] : 1, argument_count > 1 ? argument[1] : 6);
then it works for:

var a = rnd();
var a = rnd(3);
var a = rnd(5,6);
 
Yes, I am aware that I can create a script like this. that's what I currently do. however, without input from the devs, I don't really see a reason why macros can't be used this way since my understanding is that they just replace one value with the other, before the project is compiled. being able to use macros like this would bypass the overhead (small overhead, I know) used when calling scripts.
 

Gradius

Member
I believe the code is run to a degree to do this, you can use functions and maths in your macros unless something has changed. So it isn't just that GM finds and replaces the text before compiling.
 

xot

GMLscripter
GMC Elder
There are a few(?) functions that can be precomputed and then used to replace a macro. Same for switch cases. These have to behave like constants or literals. An example is ord() which always produces the same value for a given input.
 
Top