1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 How to create a C/C++ type macros in GM

Discussion in 'Programming' started by Ojars, Feb 24, 2019.

  1. Ojars

    Ojars Member

    Joined:
    Jan 28, 2018
    Posts:
    2
    Is it possible to define a C/C++ type macros in GM 1.4.9999? In C/C++ I define like this:

    #define SH5 5
    #define RSH5(val) (val) >> SH5

    and then use the macro: int x = RSH5(player.x);

    I have read the manual, and it seems to me that it's not possible. Perhaps, there is a way to achieve this in some other manner?
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,435
    In GMS2, you could do a multi-part macros
    Code:
    #macro RSH5a ((
    #macro RSH5b ) >> 5)
    // ...
    var x = RSH5a player.x RSH5b;
    
    I've been considering adding a preprocessor to GMEdit so that you could do
    Code:
    #macrofn RSH5(x) ((x) >> 5)
    // ...
    var x = RSH5(player.x);
    and it would transform to the above in the actual saved file, but it seemed a little too exotic to be actually worth the time in any practical sense.

    In GMS1, you are mostly out of luck - IDE will not let you run code that looks malformed (prior to expanding macros), so your macros must look like a valid expression (even if they aren't). The exception to this rule is GML scripts inside extensions - you can do whatever you want there, only the compiler (which knows better) will check them.
     
  3. Ojars

    Ojars Member

    Joined:
    Jan 28, 2018
    Posts:
    2
    Thank You for reply; It's not a big pain, simply I'm used to macros when I write code in C++. Happily, yesterday I started to use GMedit, and found it very
    convenient. Much better than GM code editor.
    I'm not going to purchase GM2, mostly because I write small games (old game remakes) for my grandchildren in MS Visual Studio. Then decided to port a game to GM 1.4, simply for fun. You can ask why Game Maker? Because the syntax is identical to C/C++, and it is very interesting to learn new things. Thank You for GMedit and other things you do for GM.
     
    YellowAfterlife likes this.

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