<RetVar> = The name for the sorted array, this can be the same as the array to be sorted. This array does not have to be pre created, this command will create the new array if it does not exsist.
<Value> = The array that you want to sort the values for.
Sorts the contents of an array alphabetically if it is an alphanumeric list or in ascending order if a numerical list. Numerical will take precedence over alphanumerical.
It should be noted that when sorting includes numerical values, 'lexicographical' (also known as alphanumeric order, dictionary order, alphabetical order ...) sorting is used, a Wiki explanation can be found here. What this means is basically that numerical / integers are treated as 'strings', thus do not follow the conventional numbering system we are used to. Please see 'Known Sorting Issues:' below, for an example of this behaviour.
Example:
$station.array = $sector get station array from sector
$sorted.array = sort array $station.array
The array $sorted.array will now be sorted in decending alphanumeric order.
Known Sorting Issues:
Code: Select all
$Numbers = array alloc: size=6
$Numbers[0] = 4
$Numbers[1] = 2
$Numbers[2] = 24
$Numbers[3] = 6
$Numbers[4] = 12
$Numbers[5] = 1
$Numbers = sort array $Numbers
write to player logbook $Numbers
In layman's terms it's simply doing a string sort (on integers) where "12" naturally comes before "2" because "1" comes before "2".
To overcome this issue, the following command can be used,
<RetVar> = sort array: data= <Value> sort values= <Value>
In this case,
Code: Select all
$Numbers = sort array: data= $Numbers sort values= $Numbers
Command location:
- »» General Commands
- »» Arrays
<RetVar> = sort array <Value>
- »» Arrays