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

Question - Code Order Of Operations

Discussion in 'GameMaker Studio 2 Community Tech Support' started by samspade, Dec 3, 2019.

  1. samspade

    samspade Member

    Feb 26, 2017
    I've been looking into some of the basics of GML recently and when I was looking at operator precedence I came across this page in the manual: Expressions. It claims that: "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."

    This makes some sense, however, it goes on to add that:

    a = b == c || d;
    a = (b == c || d); //better
    a = ((b == c) || d); //best
    That seems ridiculous. The only reason for the middle one being better is if this is a possible evaluation of the first line:

    (a = b) == c || d;
    Is it really this undefined? I would have assumed there was at least some consistency for order across all platforms on basic stuff like assignment or comparisons. For example:

    //would this ever be evaluated as
    if 5 * 2 == 10 * 1 {
    if 5 * (2 == 10) * 1 {
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Apr 13, 2016
    The example is meant to illustrate a point, not be taken as a "real world" example. :)

    Basically, the manual is saying, "don't rely on order of operations across all platforms as that may not work or may be changed behind the scenes". It's good practice to be explicit and it prevents future potential errors when you compile using YYC or on another target platform.
    Cpaz 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