Jump to content
Sign in to follow this  
ios

Problem with a script using "while" and "distance"

Recommended Posts

Hello, i am trying to make this script working, it places an object (here _missionlocation) around an object (here _myunitsleader) all work till here but i want it, if the object is less than 500m away from _unit1,_unit2,_unit3 and _unit4 to select a new pos its why i use "while", i want it to get a new pos till the position be 500m away from my units, the script work but sometime the object is placed 300m away from units and i get hint telling me correct position were found >.>

_location = false;

_distanceValue1 =0;

_distanceValue2 =0;

_distanceValue3 =0;

_distanceValue4 =0;

while {(!_location) AND (_distanceValue1 < 500) AND (_distanceValue2 < 500) AND (_distanceValue3 < 500) AND (_distanceValue4 < 500)} do

{

hint "looking for position...";

sleep 1;

_missionLocation setPos [(getPos _MyUnitsLeader select 0) + ((random 1000 )+(random -1000)),(getPos _MyUnitsLeader select 1) + ((random 1000 )+(random -1000)),0];

_isFlat = (getpos _missionLocation) isflatempty [

(sizeof typeof _MyUnitsLeader) / 2, //--- Minimal distance from another object

0, //--- If 0, just check position. If >0, select new one

0.7, //--- Max gradient

(sizeof typeof _MyUnitsLeader), //--- Gradient area

0, //--- 0 for restricted water, 2 for required water,

false //--- True if some water can be in 25m radius

//--- Ignored object

];

sleep 1;

if ((count _isFlat == 3)) then {_location = true} else {_location = false};

_distanceValue1 =_unit1 distance _missionLocation;

_distanceValue2 =_unit2 distance _missionLocation;

_distanceValue3 =_unit3 distance _missionLocation;

_distanceValue4 =_unit4 distance _missionLocation;

sleep 1;

};

hint "Correct position found!";

_marker = createMarker ["Marker", position _missionLocation];

"Marker" setMarkerType "Warning";

i did several try and try again before asking you dear community but if anyone can help or just try to help , many thanks in advance

Share this post


Link to post
Share on other sites

You're exiting the loop before it checks for the individual distance. Try putting the if-statement below the newly defined distance values.

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  

×