barbolani 198 Posted May 19, 2014 Hi all! I want to calculate a spawn pos from certain position. The only two conditions: no water, and not being close of an array of markers. This is my method: _closestdist = 0; _pos = [0,0,0]; while {(_closestdist < 400) and (surfaceIsWater _pos)} do { _pos = [_posicion, 400, random 360] call BIS_Fnc_relPos; _closest = [marcadoresCSAT, _pos] call BIS_fnc_nearestPosition; _closestdist = (getMarkerPos _closest) distance _pos; }; Works, but sometimes I find positions in water and, sometimes, positions less than 400 metres close from those markers. Starting to think the loop breaks when tries a lot of times, or something like this. Thanks for the help. Share this post Link to post Share on other sites
champ-1 40 Posted May 19, 2014 Don't put conditions in "while do" loop. It's not very reliable for some reason. while {true} do { private ["_goodpos"]; _goodpos = true; _pos = [_posicion, 400, random 360] call BIS_Fnc_relPos; if (!surfaceIsWater _pos) then { { if (_pos distance (getMarkerPos _x) < 400) exitWith {_goodpos = false}; } forEach Some_Marker_array; } else { _goodpos = false; }; if (_goodpos) exitWith {player globalChat "Good position found"}; }; Share this post Link to post Share on other sites
barbolani 198 Posted May 20, 2014 Thanks! Will try ASAP! Share this post Link to post Share on other sites
zapat 56 Posted May 20, 2014 What do you mean "it's not reliable"? What is not reliable and why? Share this post Link to post Share on other sites
champ-1 40 Posted May 20, 2014 (edited) I have no idea. It just doesn't work sometimes. Maybe I use it wrong or something. But I have seen same issue in other scripts, like MCC evac script. Which relies on many "while do" conditions and fails every time after couple uses. Edited May 20, 2014 by Champ-1 Share this post Link to post Share on other sites
barbolani 198 Posted May 20, 2014 It seems to work, by now... :) Thank you very much. If I find more weird things, I'll post here. Share this post Link to post Share on other sites
bangabob 45 Posted May 21, 2014 Don't put conditions in "while do" loop. It's not very reliable for some reason. Seconded. It seems much more reliable to use exitwith command. If you want to be extra safe use a variable as the loop condition and make it false inside the exitwith scope. Share this post Link to post Share on other sites