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

setting variables inside conditions

CloseRange

Member
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.
 

Mert

Member
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 --.
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.
 
Top