Jump to content
SnowmaneYT

doMove, how to know when is completed?

Recommended Posts

Hello,

 

I have _nul = _this doMove _destination; to move a unit.

What i need is when the unit reached the destination, wait for x time and then doMove to another destination. So, the big question here is, how i can detect when doMove is completed?

 

Thanks!

Share this post


Link to post
Share on other sites
On 2/4/2020 at 3:50 PM, RCA3 said:

Try unitReady

RCA3 is right.  Note in some rare weird cases units never return unitReady to True.  If you want to force unitReady to true, this usually works:

_dude domove getposatl _dude;

 

  • Like 3

Share this post


Link to post
Share on other sites

I resolved using 

waitUntil {unitReady _this};

Thanks anyway, i going to test your solution to learn more!

  • Like 3

Share this post


Link to post
Share on other sites

My experience with UnitReady command has been that the check needs to be made where the unit being checked is local.  Where the unit is not local, it always return true whether the unit is ready or not.

  • Like 2

Share this post


Link to post
Share on other sites

According to the documentation though, the unit is "busy" when given (executing) an order. Has anyone checked if this is true only for explicit orders?

 

Additionally, if you use AI mods such as VCOM, or ASR AI3,  they may issue commands to the units, which could potentially ruin the UnitReady behaviour... I haven't tested that but it's a thought.

 

One more, minor thing here is that you could possibly ease the "burden" the WaitUntil puts on your CPU by adding a short Sleep in there. Since you, most probably, don't need to check that every frame you could add a sleep 0.5; in there to save some CPU. The difference will most probably be not even noticed, but it's nice to try and save some CPU whenever you can, especially if the "trick" does not complicate the code too much. You can see an example here (example 3 in the documentation page).

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, ZaellixA said:

According to the documentation though, the unit is "busy" when given (executing) an order. Has anyone checked if this is true only for explicit orders?

I'm sure that issuing a doMove command via a script causes unitReady to be false until unit has completed the move.

 

2 hours ago, ZaellixA said:

Additionally, if you use AI mods such as VCOM, or ASR AI3,  they may issue commands to the units, which could potentially ruin the UnitReady behaviour... I haven't tested that but it's a thought.

True, these scripts could be issuing doMove commands to a unit.

2 hours ago, ZaellixA said:

One more, minor thing here is that you could possibly ease the "burden" the WaitUntil puts on your CPU by adding a short Sleep in there. Since you, most probably, don't need to check that every frame you could add a sleep 0.5; in there to save some CPU. The difference will most probably be not even noticed, but it's nice to try and save some CPU whenever you can, especially if the "trick" does not complicate the code too much. You can see an example here (example 3 in the documentation page).

You recommend a good practice.  Waituntils should have sleeps unless tracking something really fast.

  • Like 1

Share this post


Link to post
Share on other sites
On 2/9/2020 at 11:58 AM, johnnyboy said:

 

You recommend a good practice.  Waituntils should have sleeps unless tracking something really fast.

Isn't that an old wives tale?

Share this post


Link to post
Share on other sites
On 2/11/2020 at 3:12 PM, AZCoder said:

Isn't that an old wives tale?

Not sure about it... It seems quite reasonable to assume that by sleeping in a waitUntil will "skip" (not execute) the code after it (until the appropriate amount of time has passed of course). This means that, depending on the complexity of the code after the sleep command, you may save some CPU cycles.

 

Please correct me if I am wrong (if you have information showing the opposite or you have performed any tests yourself), as this is something that I always took for granted.

Share this post


Link to post
Share on other sites

waitUntil will at most check once per frame.

If you don't need to check every frame its certainly recommended to add a sleep.

  • Like 1

Share this post


Link to post
Share on other sites

Related question, instead of UnitReady, maybe we could count the waypoint/s of the group using the doMove or move command and if waypoints == 0 execute something.

 

if (count (waypoints _group) == 0) then {

_group move _destination;
or
_group doMove _destination;

};

 

Share this post


Link to post
Share on other sites
2 hours ago, Robustcolor said:

Related question, instead of UnitReady, maybe we could count the waypoint/s of the group using the doMove or move command and if waypoints == 0 execute something.

 

It's possible.  You can do a simple experiment in the editor to prove/disprove the idea.

Share this post


Link to post
Share on other sites
11 hours ago, johnnyboy said:

It's possible.  You can do a simple experiment in the editor to prove/disprove the idea.

Hm, can't seem to get it to work.

_group = [getMarkerpos "respawn_east", EAST, 7 ] call BIS_fnc_spawnGroup; 
_destination = (getMarkerPos "Marker1");

private ["_group","_destination"];
while {true} do {
uiSleep 5;

if ((count (waypoints _group)) == 0) then {
_group move _destination;
};

};

Never executes the code.

Share this post


Link to post
Share on other sites

During mission, any group has always a first waypoint for its actual position. You can test that by: count waypoints _group on any static group.

 

So you can check for == 1 or improve your code:

private _group = [getMarkerpos "respawn_east", EAST, 7 ] call BIS_fnc_spawnGroup;

private _destination = (getMarkerPos "Marker1");

_group move _destination;

 

for exactly same intended result (your loop is useless)

Note: move doesn't create a waypoint. So, the count stays at one. If you need a condition on waypoints count, use addWaypoint.

 

As said above, unitready is your solution. these guys will die at destination:
 

Spoiler

 

0 = [] spawn {

  private _group = [getMarkerpos "respawn_east", EAST, 7 ] call BIS_fnc_spawnGroup;
  private _destination = (getMarkerPos "Marker1");
  _group move _destination;
  waitUntil {sleep 0.5; unitReady leader _group};
  {_x setdamage 1} count units _group;
};

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 2/5/2020 at 10:47 AM, SnowmaneYT said:

Hello,

 

I have _nul = _this doMove _destination; to move a unit.

What i need is when the unit reached the destination, wait for x time and then doMove to another destination. So, the big question here is, how i can detect when doMove is completed?

 

Thanks!

 

 

You could put a trigger at the destination.

 

 

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

×