Jump to content
Sign in to follow this  
RolloTomassi

"waituntil" problem

Recommended Posts

Hello, i have an problem with the "waituntil" command in my sqf script. It doesn´t works with distance command.

_troop = team1;

_mark = createMarker ["mark1",[0,0,0]]; 

mapclick = false;
onMapSingleClick """mark1"" setMarkerPos _pos; clickpos = _pos; mapclick = true; onMapSingleClick """";true;";

waituntil {mapclick};
_pos = clickpos;

_mark setMarkerColor "colorRed";
_mark setMarkerShape "icon";
_mark setMarkerSize [1,1];
_mark setMarkerDir 0;
_mark setMarkerType "hd_destroy";
_log = "logic" createVehicleLocal [0,0,0];
_log setPos _pos;

sleep 2 +random 3;
_wayp1 = _troop addwaypoint [_pos,1];
[_troop,1] setWaypointType "move";
[_troop,1] setWaypointPosition [position _log,0];
_troop setCurrentWaypoint [_troop,1];
hint "CHECK 1";

waituntil {leader _troop distance _log < 50};
hint "END of SCRIPT";

The last hint - "END of SCRIPT" wil not be reached. The problematic line is:

waituntil {leader _troop distance _log < 50};

Share this post


Link to post
Share on other sites

Edit. Sorry did not see there was some more code after the mapclick = true; :D

Share this post


Link to post
Share on other sites

Perhaps try a couple of brackets:

waituntil {(leader _troop distance _log) < 50};

or maybe restructuring the code:

while {!((leader _troop distance _log) < 50)} do {sleep 0.1};

Not tested BTW, just giving some ideas :)

Share this post


Link to post
Share on other sites

I don't know how Arma 2 handles ambiguity, so this may or may not be the issue:

leader _troop distance _log

Might be interpeted as:

leader (_troop distance _log)

Rather than:

(leader _troop) distance _log

Obviously you want the second, so might as well write it like that as well. If it doesn't solve your issue at least your code will be more readable ;)

Share this post


Link to post
Share on other sites

Have you tried doing something like

hint format ["%1", getPos _troop]

and

hint format ["%1", getPos _log];

into radio calls and seeing if they are actually within 50 meters of each other?

(Change the variables so they aren't private in scope first though)

Share this post


Link to post
Share on other sites

You can no longer create Logic objects through createVehicle and should use createUnit. You can compare the case to trying to create a soldier using createVehicle. Your script could not continue because _log is a null-object. Try:

_log = _troop createUnit ["Logic", [0, 0, 0], [], 0, "NONE"];

Note 1: avoid position [0, 0, 0] where you can, it's dangerous :)

Note 2: create a dedicated group for the Logic on side sideLogic. This will be the safest and in the future may become required for Logic objects.

Share this post


Link to post
Share on other sites
Note 1: avoid position [0, 0, 0] where you can, it's dangerous

Hmm, I use this extensively in my scripts. What do you recommend instead ? [1,1,1,] or some other location ?

Share this post


Link to post
Share on other sites
nothing works :(((

There is something else wrong. That script in your first post works just fine. I opened a new mission, pasted your code into an sqf file etc. Worked nicely.

Share this post


Link to post
Share on other sites

Thanks for the hints DNA !

always was courious why you guys now set [1,1,1] instead of [0,0,0] and already started to change my habits too, particularely since I noticed that move commands tend to be ignored by outside_of_map units.

However I allso still use vehiclelocal without problems for logics yet. I take it its better to change this habit for future versions, too ?

RolloTomasi:

maybe your variable team1 is the culprit.

Are you sure its a group you are referencing to ?

otherwise the leader function wouldnt return something "useful" ...

did you check arma2.rpt or set start parameter -showScriptErrors for errors ?

Share this post


Link to post
Share on other sites

Ok, i set now hint message in the script:

hintC format ["troop - %1\n_Log - %2\n_Log dist troop - %3\nleader troop - %4",_troop,_Log,_Log distance leader _troop,leader _troop];

The effect:

troop - B 1-1-C
_Log - <No group>:0
_Log dist troop - 278.749
leader troop - men2

But the horizontal distance to the logic object is only 80~100 meters. Can the problem be the vertical position? The location of the group is in the hills.

Share this post


Link to post
Share on other sites

yes, distance returns the absolute distance (3D) iirc

Share this post


Link to post
Share on other sites

I tested it on the coast and now it is working. But not in the hills.

What i must do to positioning the Logic object on the ground height?

_pos = clickpos;
_Log setPos _pos;

Share this post


Link to post
Share on other sites

I have it:

_Log setPos _pos;
_Log setPos [(getPos _Log select 0),(getPos _Log select 1),1];

Thanks all for the help.

Share this post


Link to post
Share on other sites

do you execVM this script?

edit: nevermind, i have not readed latest posts...

Edited by dfear

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  

×