deleteWaypoint: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(see also)
m (Add forEachReversed example)
 
(104 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma |= Game name
|game1= ofpe
|version1= 1.00


|1.00|= Game version
|game2= arma1
|version2= 1.00


|arg= global |= Arguments in MP
|game3= arma2
|version3= 1.00


|eff= global |= Effects in MP
|game4= arma2oa
____________________________________________________________________________________________
|version4= 1.50


| Removes the specified waypoint. |= Description
|game5= tkoh
____________________________________________________________________________________________
|version5= 1.00


| '''deleteWaypoint''' [group, index] |= Syntax
|game6= arma3
|version6= 0.50


|arg= global


|p1= [group, index]: [[Array]] |= Parameter 1
|eff= global
|p2=  group: [[Group]] |= Parameter 2
|p3= index: [[Number]] |= Parameter 3


| [[Nothing]] |= Return value
|gr1= Waypoints
____________________________________________________________________________________________
 
|x1= <pre>deleteWaypoint [_grp, 2]</pre> |= Example 1
____________________________________________________________________________________________


| [[waypoints]], [[copyWaypoints]], [[setCurrentWaypoint]], [[setWaypointBehaviour]], [[setWaypointCombatMode]], [[setWaypointCompletionRadius]], [[setWaypointDescription]], [[setWaypointFormation]], [[setWaypointHousePosition]], [[setWaypointPosition]], [[setWaypointScript]], [[setWaypointSpeed]], [[setWaypointStatements]], [[setWaypointTimeout]], [[setWaypointType]], [[setWaypointVisible]], [[waypointAttachVehicle]], [[waypointAttachedVehicle]], [[setWaypointLoiterRadius]], [[waypointLoiterRadius]], [[addWaypoint]], [[setWaypointLoiterType]] |= See also
|descr= Removes the specified waypoint.
{{Feature|informative|
* When a waypoint is deleted, all other [[group]] [[waypoints]] are immediately re-indexed. See {{Link|#Example 2}} for a deletion of all group's waypoints.
* Deleting a group's [[currentWaypoint|current waypoint]] will ''not'' stop the group on its tracks.
}}


}}
|s1= [[deleteWaypoint]] [group, index]
 
|p1= group: [[Group]]


<h3 style="display:none">Notes</h3>
|p2= index: [[Number]]
<dl class="command_description">
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on 1 Feb, 2008 - 07:48
<dt class="note">[[User:Saintolaf|Saintolaf]]
<dd class="note">
In order to change the behavior of a unit currently following a string of waypoints, it is not enough to use deleteWaypoint. The path of the unit is calculated by the waypoints present at start, and the unit will continue according to the original waypoints even if you delete them by using this command.
To achieve the wanted effect, you should rather use setWPPos to the units current position (thereby stopping the unit), and (after a small delay) use deleteWaypoint to remove the waypoints.


<dd class="notedate">Posted on 15 Nov, 2008 - 13:37
|r1= [[Nothing]]
<dt class="note">'''[[User:VictorFarbau|VictorFarbau]]'''
<dd class="note">
Another (more foolproof) method to avoid the problem of non-deleteable waypoints is to introduce another group (createGroup) and join all units of the present group. A new group will start without any preset waypoints so you can start setting new WPs all over again.
Example:
Old group is "_combatGroup", new group is "_combatGroup2"
<code>_combatGroup2 = createGroup EAST;
{[_x] joinSilent _combatGroup2} forEach (units _combatGroup);
_combatGroup2 addWaypoint [getPos player, 25];</code>


|x1= <sqf>deleteWaypoint [_grp, 2];</sqf>


<dd class="notedate">Posted on January 04, 2011
|x2= Because waypoints get immediately re-indexed when one gets deleted, delete them from last to first:
<dt class="note">'''[[User:kju|kju]]'''
<sqf>
<dd class="note">
private _group = group _unit;
When you want to remove all waypoints, do '''NOT''' iterate over ''waypoints _group'' while trying to delete them (an array is by reference!). Instead use an approach like this:
for "_i" from (count waypoints _group - 1) to 0 step -1 do
<code>
{
while {(count (waypoints _group)) > 0} do
deleteWaypoint [_group, _i];
{
};
  deleteWaypoint ((waypoints _group) select 0);
</sqf>
};</code>
or always delete the first one (if you want to delete them all)
<sqf>
private _group = group _unit;
for "_i" from 0 to (count waypoints _group - 1) do
{
deleteWaypoint [_group, 0];
};
</sqf>
or use [[forEachReversed]]:
<sqf>
{ deleteWaypoint _x } forEachReversed waypoints _group; // Arma 3 v2.14+ only
</sqf>


<dd class="notedate">Posted on 13 Mar, 2012 - 10:51
|seealso= [[waypoints]] [[setCurrentWaypoint]] [[setWaypointPosition]] [[setWaypointScript]] [[setWaypointStatements]] [[setWaypointType]] [[addWaypoint]]
<dt class="note">'''[[User:ArmAriffic|ArmAriffic]]'''
}}
<dd class="note">
You can also remove all waypoints with
<code>deleteWaypoint [_group, all];</code>
<!-- Note Section END -->
</dl>


<h3 style="display:none">Bottom Section</h3>
{{Note
|user= Saintolaf
|timestamp= 20080101074800
|text= In order to change the behavior of a unit currently following some waypoints, it is not enough to use [[deleteWaypoint]].
To achieve the wanted effect, you should rather use [[setWPPos]] to the unit's current position (thereby stopping the unit), and (after a small delay) use [[deleteWaypoint]] to remove the next [[waypoints]].
}}


[[Category:Scripting Commands|DELETEWAYPOINT]]
{{Note
[[Category:Scripting Commands OFP Elite |DELETEWAYPOINT]]
|user= VictorFarbau
[[Category:Scripting Commands ArmA|DELETEWAYPOINT]]
|timestamp= 20081115133700
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
|text= Another (more foolproof) method to avoid the problem of non-deleteable waypoints is to introduce another group ([[createGroup]]) and [[join]] all units of the present group. A new group will start without any preset waypoints so you can start setting new WPs all over again.
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
Old group is "_combatGroup", new group is "_combatGroup2"
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
<sqf>
[[Category:Command_Group:_Waypoints|{{uc:{{PAGENAME}}}}]]
_combatGroup2 = createGroup east;
{ [_x] joinSilent _combatGroup2 } forEach (units _combatGroup);
_combatGroup2 addWaypoint [getPos player, 25];
</sqf>
}}
 
{{Note
|user= Mr H.
|timestamp= 20191117165200
|text= To have the unit stop on the spot you need to set its current waypoint where it is and add a little delay, as stated above by [[User|Saintolaf]] so:
 
<sqf>
group _unit spawn
{
[_this, currentWaypoint _this] setWaypointPosition [getPosASL ((units _this) select 0), -1];
sleep 0.1;
for "_i" from count waypoints _this - 1 to 0 step -1 do
{
deleteWaypoint [_this, _i];
};
};
</sqf>
Will stop the group where it is and delete its waypoints.
}}

Latest revision as of 18:09, 27 April 2023

Hover & click on the images for description

Description

Description:
Removes the specified waypoint.
  • When a waypoint is deleted, all other group waypoints are immediately re-indexed. See Example 2 for a deletion of all group's waypoints.
  • Deleting a group's current waypoint will not stop the group on its tracks.
Groups:
Waypoints

Syntax

Syntax:
deleteWaypoint [group, index]
Parameters:
group: Group
index: Number
Return Value:
Nothing

Examples

Example 1:
deleteWaypoint [_grp, 2];
Example 2:
Because waypoints get immediately re-indexed when one gets deleted, delete them from last to first:
private _group = group _unit; for "_i" from (count waypoints _group - 1) to 0 step -1 do { deleteWaypoint [_group, _i]; };
or always delete the first one (if you want to delete them all)
private _group = group _unit; for "_i" from 0 to (count waypoints _group - 1) do { deleteWaypoint [_group, 0]; };
or use forEachReversed:
{ deleteWaypoint _x } forEachReversed waypoints _group; // Arma 3 v2.14+ only

Additional Information

See also:
waypoints setCurrentWaypoint setWaypointPosition setWaypointScript setWaypointStatements setWaypointType addWaypoint

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Saintolaf - c
Posted on Jan 01, 2008 - 07:48 (UTC)
In order to change the behavior of a unit currently following some waypoints, it is not enough to use deleteWaypoint. To achieve the wanted effect, you should rather use setWPPos to the unit's current position (thereby stopping the unit), and (after a small delay) use deleteWaypoint to remove the next waypoints.
VictorFarbau - c
Posted on Nov 15, 2008 - 13:37 (UTC)
Another (more foolproof) method to avoid the problem of non-deleteable waypoints is to introduce another group (createGroup) and join all units of the present group. A new group will start without any preset waypoints so you can start setting new WPs all over again. Old group is "_combatGroup", new group is "_combatGroup2"
_combatGroup2 = createGroup east; { [_x] joinSilent _combatGroup2 } forEach (units _combatGroup); _combatGroup2 addWaypoint [getPos player, 25];
Mr H. - c
Posted on Nov 17, 2019 - 16:52 (UTC)
To have the unit stop on the spot you need to set its current waypoint where it is and add a little delay, as stated above by Saintolaf so:
group _unit spawn { [_this, currentWaypoint _this] setWaypointPosition [getPosASL ((units _this) select 0), -1]; sleep 0.1; for "_i" from count waypoints _this - 1 to 0 step -1 do { deleteWaypoint [_this, _i]; }; };
Will stop the group where it is and delete its waypoints.