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

[SOLVED] Logical Expressions Question

M

Maximus

Guest
How do logical expressions work in GML? For example, with an if statement like this:
Code:
if ( <expression 1> && <expression2> )
{
    // do something
}
if the first expression evaluates to be false, will the second expression be evaluated or just skipped over?

If <expression2> was particularly taxing to evaluate, and <expression1> is rarely true, then should I make it a nested if statement or is this unnecessary?
Code:
if ( <expression 1> )
{
    if ( <expression2> )
    {
        // do something
    }
}
 
Last edited by a moderator:
M

Maximus

Guest
GML stops evaluation when it runs into something that results in false. They made a blog post about this when they changed how GML evaluates things.
Awesome, thanks. The blog only mentions &&, can I also assume short circuit evaluation applies for || when an operand is true?
 
Awesome, thanks. The blog only mentions &&, can I also assume short circuit evaluation applies for || when an operand is true?
That's incorrect, as it won't be able to determine if the entire expression is false until it evaluates all || operators.

Edit: *facepalm* ... Actually read what you asked this time. Yes, that is true. Ignore my dumb arsed initial comment.
 
Top