BIS fnc sortBy: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " <h3 style="display:none">Notes</h3> <dl class="command_description"> <!-- Note Section BEGIN --> <!-- Note Section END --> </dl> " to "") |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(13 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{RV|type=function | ||
| arma3 | | |game1= arma3 | ||
|version1= 0.58 | |||
| | |gr1= Arrays | ||
| | |descr= Sorts an array according to given algorithm. See [[sort]] for simple sorts. | ||
| | |s1= [array, parameters, algorithm, direction, filter] call [[BIS_fnc_sortBy]] | ||
|p1= array: [[Array]] - any unsorted array. Can contain any types | |||
|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) | * a maximum of 10 input params is supported (0-9) | ||
|p3= algorithm: [[Code]] - (Optional, default { | |p3= algorithm: [[Code]] - (Optional, default <sqf inline>{ _x }</sqf>) | ||
* needs to return [[String]], [[Number]] or [[Array]] - see [[sort]] | * needs to return [[String]], [[Number]] or [[Array]] - see [[sort]] | ||
* [[_x]] refers to array item | * [[Magic Variables#x|_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 | * "DESCEND" (or anything else) for descending sorting | ||
|p5= filter: [[Code]] - (Optional, default { | |p5= filter: [[Code]] - (Optional, default <sqf inline>{ true }</sqf>) code that needs to evaluate true for the array item to be sorted, otherwise item is removed | ||
| [[Array]] - sorted array | |r1= [[Array]] - sorted array | ||
|x1= < | |x1= <sqf> | ||
_sortedNumbers = [ | // sort numbers from lowest to highest | ||
_sortedNumbers = [[1,-80,0,480,15,-40], [], {_x}, "ASCEND"] call BIS_fnc_sortBy; | |||
</sqf> | |||
|x2= < | |x2= <sqf> | ||
_closestHelicopters = [ | // sort helicopters by distance from player | ||
_closestHelicopters = [[_heli1,_heli2,_heli3], [], { player distance _x }, "ASCEND"] call BIS_fnc_sortBy; | |||
</sqf> | |||
|x3= < | |x3= <sqf> | ||
_furtherstEnemy = [ | // 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; | |||
</sqf> | |||
| [[BIS_fnc_sortAlphabetically]] | |seealso= [[BIS_fnc_sortAlphabetically]] [[BIS_fnc_sortNum]] [[sort]] | ||
}} | }} | ||
Latest revision as of 14:57, 13 July 2022
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:
- Example 2:
- Example 3:
Additional Information
- See also:
- BIS_fnc_sortAlphabetically BIS_fnc_sortNum sort
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