• 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 Correct order of operations? (SOLVED)

Fixer90

Member
In GML, let's say I have the following equation:
Code:
a = 2 + b / 150 * (c - 1) * 3
According to the order of operations, this essentially translates to
Code:
a = 2 + ((b / 150) * (c - 1) * 3)
But will GML automatically do the steps in the right order, as the order of operations would, or do I need to include the parentheses?
 
D

dannyjenn

Guest
It should, but I just checked the help file and it says we still need to use parentheses because it could vary from platform to platform.
When doing multiple operations in a single expression, it is very important that you use brackets () to separate out the order of operation, as different platforms may perform them differently if not explicitly stated in this way.
(emphasis in the text)

Here is the relevant page from the help file: https://docs2.yoyogames.com/source/_build/3_scripting/3_gml_overview/12_expressions.html

Though, I'm a little confused as to why it has assignment listed as top priority. I would think it would have lowest priority. The entire expression needs to be evaluated before any assignment can be made.
 
Assignment might be last in maths, but my guess is it'd have something to do with pointers in coding and so you'd need to pass the indexs around before manipulating (or something like that).
 
Top