Feedback Suggestion: Aliases via macros

Discussion in 'GameMaker Studio 2 Community Tech Support' started by stainedofmind, Dec 6, 2016.

  1. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    644
    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?
     
  2. gnysek

    gnysek Member

    Joined:
    Jun 20, 2016
    Posts:
    1,186
    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);
     
  3. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    644
    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.
     
  4. Gradius

    Gradius Member

    Joined:
    Jun 21, 2016
    Posts:
    59
    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.
     
  5. xot

    xot GMLscripter GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    108
    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.
     
  6. rwkay

    rwkay YoYo Games Staff YYG Staff

    Joined:
    Apr 12, 2016
    Posts:
    1,047
    I have fixed this in the internal build - but that will not make it out until after Christmas now

    Russell
     
    xot, stainedofmind and MaddeMichael like this.
  7. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    644
    Awesome. Thanks Russell! With that, I'm going to say that macros are now officially perfect! :p
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice