BIS fnc sortBy: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "\| *((\[\[[a-zA-Z0-9_ :\\\-\/|()]+\]\],? ?)+) * \}\}" to "|seealso= $1 }}") |
Lou Montana (talk | contribs) |
||
Line 18: | Line 18: | ||
* 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 { [[_x]] }) | |p3= algorithm: [[Code]] - (Optional, default { [[Magic Variables#x|_x]] }) | ||
* 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 |
Revision as of 12:58, 25 February 2021
Description
- Description:
- Description needed
- Execution:
- call
- Groups:
- Arrays
Syntax
- Syntax:
- Syntax needed
- 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:
- Return value needed
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
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