Question - Code Ternary Operators and the YYC

Discussion in 'GameMaker Studio 2 Community Tech Support' started by IGameArt, Jan 31, 2019.

  1. IGameArt

    IGameArt Member

    Joined:
    Jun 21, 2016
    Posts:
    123
    Okay, so since the bugfix for this issue has been pushed back to runtime version 2.2.3, at least another 3+ months away, and I can't afford to wait that long, I'd like to try and see under what kinds of circumstances the ternary operators actually compile using the yyc module.

    I know, from the bug report the following code will fail:

    Code:
    var arg0 = 5;
    return (arg0 > 0 ? arg0 : -arg0)
    I'll be posting my own experiments with ways that ternary operators won't cause the compiler to throw an error, but if anyone else out there has experience in this, please feel free to post your findings as well so that we can help the community as a whole while we wait for this fix to be released.
     
  2. TheSpydog

    TheSpydog Member

    Joined:
    Jun 20, 2016
    Posts:
    63
    Alternatively, as a workaround, you could replace all instances of the ternary operator with something like the good old iif() script:
    Code:
    // iif(condition, value1, value2)
    
    if (argument0)
    {
        return argument1;
    }
    else
    {
        return argument2;
    }
    It's not optimal but it'd get the job done. Shouldn't be too hard to find+replace either, since you could likely search the project for "?" or ":" and get most of the occurrences.
     
  3. IGameArt

    IGameArt Member

    Joined:
    Jun 21, 2016
    Posts:
    123
    Something like that might be one of the best options until these issues are resolved. I havent been able to test the YYC module for months so it's taking me upwards of 20 minutes to compile to the point where I find an error. It's a slow process but I'll be testing it out and I'll report back if that's not throwing any errors.

    Upon further inspection, although this method is still likely the best option, one issue that arrise is when you have code like this:
    Code:
    spawned = random(1) > 0.5 ? instance_create(x,y,object) : noone;
    
    spawned = iif( random(1)>0.5,instance_create(x,y,object),noone);
    In the first option, there are instances where instance_create will by bypassed in favor of returning "noone".

    In the second option instance_create will ALWAYS be called, there is no skipping it, that instance will still be created even if random(1) is less than 0.5, but the variable "spawned" will be assigned "noone"

    This means that extra work will need to be done, something like this:
    Code:
    spawned = iif( random(1)>0.5,true,noone);
    if spawned == true spawned = instance_create(x,y,object);
     
    Last edited: Jan 31, 2019
  4. IGameArt

    IGameArt Member

    Joined:
    Jun 21, 2016
    Posts:
    123
    I managed to talk with yoyogames on the subject this week. As it turns out it was originally marked for 2.2.2 by mistake, as they felt it needed more testing before they felt like they could release it.

    However, the good news is that it's been tested thoroughly enough for them to bump it from 2.2.3 to 2.2.2.303+ meaning the next beta update should have the ternary operators fixed finally. So I'm holding onto hope that this patch comes out soon XP
     
    gnysek likes this.
  5. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,044
    That's good to know, but I've been able to compile ternary operators in the past as long as they were properly encapsulated. ie:
    Code:
    var this = a ? b : c;
    That would fail under the compiler, but:
    Code:
    var this = ( a ? b : c );
    Would compile normally. Is there more to the bug than just "ternary" operators won't compile? In your example you use them in a return statement, is that part of the bug? Also, I'm a bit vexed by the example to begin with, it's functionally equivalent to
    Code:
    return abs( arg0 )
    Is that the specific code that is failing? Or is just a pattern that you've found to fail?
     
  6. IGameArt

    IGameArt Member

    Joined:
    Jun 21, 2016
    Posts:
    123
    @Hyomoto I just pulled that example from the bug report that I found that corroborates my problem. I don't know what the exact circumstances are that ternary operators cause a fail, being that it's a bug it could be a few circumstances.

    I'm not really looking for an alternative to the example code I've shared, but I'll attempt to see if my code doesn't fail if it's properly bracketed.
     
  7. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,044
    If there's a bug, it should be fixed. So I certainly don't mean to imply it should simply be worked around, but if this isn't working then I've been giving out bad information for a while.

    When GM2 first launched I did a bunch of tests and filed a bunch of bugs for ternary operators because they weren't working in the compiler. However, many of them were fixed. If there are more, or they broke again, I'm just interested in the cases that it's still not working.
     
  8. IGameArt

    IGameArt Member

    Joined:
    Jun 21, 2016
    Posts:
    123
    I'm not entirely sure of all the cases, it's hard to pin point. My coffee had about 50,000 lines and tons of ternary operators. But the good news is that they've renewed an update with the bugs fixed in the beta channel. I got the project to compile on yuck once before it crecras due to an error on in my code. It also took an hour to compile... So I have it building again, this time to a zip so I can let it run well I sleep and try it again in the morning. Lmao
     

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