Jump to content
Sign in to follow this  
barbolani

surfaceIsWater and others...

Recommended Posts

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

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

What do you mean "it's not reliable"? What is not reliable and why?

Share this post


Link to post
Share on other sites

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 by Champ-1

Share this post


Link to post
Share on other sites

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×