BIS fnc sortBy: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " <h3 style="display:none">Notes</h3> <dl class="command_description"> <!-- Note Section BEGIN --> <!-- Note Section END --> </dl> " to "")
m (Text replacement - " *\| *([Cc]omments|COMMENTS|[Gg]ame [Nn]ame|Game [Vv]ersion|Game Version \(number surrounded by NO SPACES\)|Multiplayer Arguments \("local" or "global"\)|Multiplayer Effects \("local" or "global"\)|Multiplayer Execution \("server" o...)
Line 1: Line 1:
{{Function|Comments=
{{Function


| arma3 |Game name=
| arma3


|0.58|Game version=
|0.58


|gr1= Arrays |GROUP1=
|gr1= Arrays


| Sorts an array according to given algorithm. See [[sort]] for simple sorts. |Description=
| Sorts an array according to given algorithm. See [[sort]] for simple sorts.


| [array, parameters, algorithm, direction, filter] call [[BIS_fnc_sortBy]] |Syntax=
| [array, parameters, algorithm, direction, filter] call [[BIS_fnc_sortBy]]


|p1= array: [[Array]] - any unsorted array. Can contain any types |Parameter 1=
|p1= array: [[Array]] - any unsorted array. Can contain any types


|p2= parameters: [[Array]]
|p2= parameters: [[Array]]
* used in the eval algorithm
* used in the eval algorithm
* input params are referenced in the sorting algorithm by _input0..9
* input params are referenced in the sorting algorithm by _input0..9
* a maximum of 10 input params is supported (0-9) |Parameter 2=
* a maximum of 10 input params is supported (0-9)


|p3= algorithm: [[Code]] - (Optional, default { [[_x]] })
|p3= algorithm: [[Code]] - (Optional, default { [[_x]] })
* needs to return [[String]], [[Number]] or [[Array]] - see [[sort]]
* needs to return [[String]], [[Number]] or [[Array]] - see [[sort]]
* [[_x]] refers to array item |Parameter 3=
* [[_x]] refers to array item


|p4= direction: [[String]] - (Optional, default "ASCEND") case-insensitive
|p4= direction: [[String]] - (Optional, default "ASCEND") case-insensitive
* "ASCEND" for ascending sorting
* "ASCEND" for ascending sorting
* "DESCEND" (or anything else) for descending sorting |Parameter 4=
* "DESCEND" (or anything else) for descending sorting


|p5= filter: [[Code]] - (Optional, default { [[true]] }) code that needs to evaluate true for the array item to be sorted, otherwise item is removed |Parameter 5=
|p5= filter: [[Code]] - (Optional, default { [[true]] }) code that needs to evaluate true for the array item to be sorted, otherwise item is removed


| [[Array]] - sorted array |Return value=
| [[Array]] - sorted array


|x1= <code>{{cc|sort numbers from lowest to highest}}
|x1= <code>{{cc|sort numbers from lowest to highest}}
_sortedNumbers = [<nowiki/>[1,-80,0,480,15,-40], [], {_x}, "ASCEND"] [[call]] [[BIS_fnc_sortBy]];</code> |Example 1=
_sortedNumbers = [<nowiki/>[1,-80,0,480,15,-40], [], {_x}, "ASCEND"] [[call]] [[BIS_fnc_sortBy]];</code>


|x2= <code>{{cc|sort helicopters by distance from player}}
|x2= <code>{{cc|sort helicopters by distance from player}}
_closestHelicopters = [<nowiki/>[_heli1,_heli2,_heli3], [], { [[player]] [[distance]] _x }, "ASCEND"] [[call]] [[BIS_fnc_sortBy]];</code> |Example 2=
_closestHelicopters = [<nowiki/>[_heli1,_heli2,_heli3], [], { [[player]] [[distance]] _x }, "ASCEND"] [[call]] [[BIS_fnc_sortBy]];</code>


|x3= <code>{{cc|sort enemy by distance from friendly unit (referenced by local variable), the furthest first}}
|x3= <code>{{cc|sort enemy by distance from friendly unit (referenced by local variable), the furthest first}}
_furtherstEnemy = [<nowiki/>[_enemy1,_enemy2,_enemy3], [_friendly], { _input0 [[distance]] _x }, "DESCEND", { [[canMove]] _x }] [[call]] [[BIS_fnc_sortBy]];</code> |Example 3=
_furtherstEnemy = [<nowiki/>[_enemy1,_enemy2,_enemy3], [_friendly], { _input0 [[distance]] _x }, "DESCEND", { [[canMove]] _x }] [[call]] [[BIS_fnc_sortBy]];</code>


| [[BIS_fnc_sortAlphabetically]], [[BIS_fnc_sortNum]], [[sort]] |See also=
| [[BIS_fnc_sortAlphabetically]], [[BIS_fnc_sortNum]], [[sort]]
}}
}}


<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>

Revision as of 23:47, 17 January 2021

Hover & click on the images for description

Description

Description:
Sorts an array according to given algorithm. See sort for simple sorts.
Execution:
call
Groups:
Arrays

Syntax

Syntax:
[array, parameters, algorithm, direction, filter] call BIS_fnc_sortBy
Parameters:
array: Array - any unsorted array. Can contain any types
parameters: Array
  • used in the eval algorithm
  • input params are referenced in the sorting algorithm by _input0..9
  • a maximum of 10 input params is supported (0-9)
algorithm: Code - (Optional, default { _x })
direction: String - (Optional, default "ASCEND") case-insensitive
  • "ASCEND" for ascending sorting
  • "DESCEND" (or anything else) for descending sorting
filter: Code - (Optional, default { true }) code that needs to evaluate true for the array item to be sorted, otherwise item is removed
Return Value:
Array - sorted array

Examples

Example 1:
// sort numbers from lowest to highest _sortedNumbers = [[1,-80,0,480,15,-40], [], {_x}, "ASCEND"] call BIS_fnc_sortBy;
Example 2:
// sort helicopters by distance from player _closestHelicopters = [[_heli1,_heli2,_heli3], [], { player distance _x }, "ASCEND"] call BIS_fnc_sortBy;
Example 3:
// sort enemy by distance from friendly unit (referenced by local variable), the furthest first _furtherstEnemy = [[_enemy1,_enemy2,_enemy3], [_friendly], { _input0 distance _x }, "DESCEND", { canMove _x }] call BIS_fnc_sortBy;

Additional Information

See also:
BIS_fnc_sortAlphabeticallyBIS_fnc_sortNumsort

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

Bottom Section