GameMaker: Studio

GameMaker: Studio

Zobrazit statistiky:
Can you do both "or" and "and" in the same statement?
Just wondering if something like this would work or not.

if (global.example==true) && (global.ovenpotato==false) || (totalenemies<3)

< >
Zobrazeno 17 z 7 komentářů
Yep.
I would use brackets to make sure the order is the way you expect.
if ((global.example==true) && (global.ovenpotato==false)) || (totalenemies<3)
MrDave původně napsal:
I would use brackets to make sure the order is the way you expect.
if ((global.example==true) && (global.ovenpotato==false)) || (totalenemies<3)
Okay, thanks.
Also you dont need to check if a boolean == true, as that is redundant.
if bool will trigger if the variable is true and if !bool will trigger if it is false.
if (global.example && !global.ovenpotato) || totalenemies < 3
Oh another thing on this topic, if you have many arguments inside an IF statement GML will calculate them all even if one has already passed or failed the criteria.

This means it is more efficient to do nested IF statements.

This:
if (a > 0) { If (a < 10) { //do } }
Is faster than this:
If (a > 0 and a < 10) { // do }
MrDave původně napsal:
Oh another thing on this topic, if you have many arguments inside an IF statement GML will calculate them all even if one has already passed or failed the criteria.
I don't think that's true anymore. I believe they updated it. I couldn't find any documentation about it so I did a test.

<start script> ///if_check() show_debug_message("if_check() executed!") return true <end script> <start first room creation event> if true && if_check() show_debug_message("test1 triggered") if !(false && if_check()) show_debug_message("test2 triggered") if true || if_check() show_debug_message("test3 triggered") if false || if_check() show_debug_message("test3 triggered") <end first room creation event> <start output> if check executed! test1 triggered test2 triggered test3 triggered if check executed! test3 triggered <end output>
This would suggest that gamemaker doesn't check all statements if it doesn't have to.
Thanks Daynar, my information was correct at one point: http://www.yoyogames.com/blog/23
YoYoGames původně napsal:
In many languages, the moment any one of the checks returns false, the rest are skipped and the next function is stepped into. However GameMaker:Studio will evaluate ALL of them, even if the first one is false. Therefore it is recommended that you "nest" your ifs
But it looks like it has been updated. Sorry for the wrong info.
< >
Zobrazeno 17 z 7 komentářů
Na stránku: 1530 50

Datum zveřejnění: 3. kvě. 2017 v 3.48
Počet příspěvků: 7