1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

setting variables inside conditions

Discussion in 'Programming' started by CloseRange, Oct 1, 2019.

  1. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    869
    This is a weird question but i was wondering if it's possible to set a variable while inside a condition.
    For example I have a script that returns either an instance of an object or false. Could I do something like this:
    Code:
    var o;
    while(o = script()) {
          show_debug_message(o.name);
    }
    I do know game maker is weird with == vs = and so I'm just worried it will try to check if o is equal to the return of script. (not how most languages work but okkkkk)

    Also, kinda related, I tried this but couldn't seem to get it to work. Maybe I have the formatting wrong but most languages you can do this:
    Code:
    var a, b;
    a = b = 10;
    
    so b gets set to 10 and a gets set to b (so both a and b are 10). I thought I remember this being a valid thing.
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,022
    while script()

    But no, that won't work.

    In your second code, a would be equal to 0 or 1. The only inline modifications you can do are ++ and --.
     
    Mert and CloseRange like this.
  3. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    869
    Thank you. I guess I can write it all out the long way was just hoping to be able to be a little lazier.
     
  4. Mert

    Mert Member

    Joined:
    Jul 20, 2016
    Posts:
    412
    Just a note, Game Maker Language will receive a major update in the following months. If I'm correct, we'll be able to do what the OP asks for then.
     

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