Icaruk 14 Posted July 31, 2014 while {a == 2} do { bla; sleep 1; }; or while {true} do { if (a == 2) then { bla; }; sleep 1; }; Share this post Link to post Share on other sites
cuel 25 Posted July 31, 2014 Well... Can we assume that "a" is always 2? Your example is kind of vague. With that code it depends on what "bla" does Share this post Link to post Share on other sites
tpw 2314 Posted August 1, 2014 The performance hit of a simple loop with a 1 sec sleep is negligible. The main difference between the code you have pasted is that first one will run bla until a!=2, and will not run again after that no matter what. The second loop will run bla if a==2, stop running bla if a!=2 , but start running bla if a==2 again. Share this post Link to post Share on other sites
barbolani 198 Posted August 1, 2014 For unknown reasons, seems conditions in a while loop are not reliable... I recommend allways a while {true} and inside of it, a condition with exitwith if no eternal loop is needed. I noticed that in a script like this: _pos = whatever position; while {surfaceIsWater _pos} do {_pos = whatever method of searching a new pos; sleep 1}; The results of that where position in water, don't ask me why, instead of that I had to do this: while {true} do {if (!surfaceIsWater _pos) exitWith {}; _pos = whatever method of searching a new pos; } Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted August 1, 2014 For unknown reasons, seems conditions in a while loop are not reliable... I recommend allways a while {true} and inside of it, a condition with exitwith if no eternal loop is needed.I noticed that in a script like this: _pos = whatever position; while {surfaceIsWater _pos} do {_pos = whatever method of searching a new pos; sleep 1}; The results of that where position in water, don't ask me why, instead of that I had to do this: while {true} do {if (!surfaceIsWater _pos) exitWith {}; _pos = whatever method of searching a new pos; } Weird, never had that happen, ever. Share this post Link to post Share on other sites
barbolani 198 Posted August 1, 2014 I discovered this on Antistasi, I use that snippet to spawn groups in random positions around a marker. After a few checks I noticed 1/5 times units were spawning in water. Asked in the forums and that was the answer: no reliable. Changed to way of doing this and no water spawning since. Don't ask me why, but as performance wise it is almost the same, no worries... Share this post Link to post Share on other sites
bangabob 41 Posted August 1, 2014 I also find the while conditions unreliable and I find that placing the if exitwith command before or after code executes is quite handy. Share this post Link to post Share on other sites