• 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!

GameMaker ("+=" / "*=") operators limitations

xDGameStudios

GameMaker Staff
GameMaker Dev.
I came across something I thought should be possible to do (at least it works with C++ and C# and JS.

if I try something like:

Code:
var m = 2

return ( ( m*= 2 ) * m + 3);
I get a syntax error, is it OK?
thank you for your time!
 
N

NPT

Guest
It doesn't make sense for the parenthesis to be on both sides of the *= as you have them.


return ( m*= 2 * m + 3);

Now, what value do you intend on returning?
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
It doesn't make sense for the parenthesis to be on both sides of the *= as you have them.


return ( m*= 2 * m + 3);

Now, what value do you intend on returning?
It doesn't make sense?! Why is that... I only wrote like that because of the multiplication order...

i didn't know if it would interfere... and BTW... you could have tried before coming here correcting people... the parentheses may be useless... but that's not the problem.. try it yourself and see! :)
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
In a number of C-like languages,
Code:
return ( ( m*= 2 ) * m + 3);
would be interpreted as
Code:
m *= 2;
return m * m + 3;
However, the tendency with newer languages is to not allow such "inline assignments", as they are nothing other than asking for trouble (if compiler evaluation order is RTL, the expression will have an entirely different value - same as with function arguments), and are overwhelmingly used to cut some lines of code at price of making it harder to read.
 
Top