[dismiss]
This wiki is a copy of the original Oblivion CS wiki created and maintained by the UESP.net. See CSwiki:Copy Notice for more info.
Difference between revisions of "Ar CustomSort"
Jump to navigation
Jump to search
Added notes and example
imported>QQuix (New page) |
imported>QQuix (Added notes and example) |
||
Line 5: | Line 5: | ||
The function should be defined to take two array_var arguments. When it is called, the arguments will contain exactly one element each - the elements to be compared. | The function should be defined to take two array_var arguments. When it is called, the arguments will contain exactly one element each - the elements to be compared. | ||
It should return true if the first argument is less than the second argument, and | It should return true if the first argument is less than the second argument, and false if it is greater than or equal to the second argument. | ||
You can define 'less', 'greater', and 'equal' in whatever way makes sense for you provided your definitions provide a definitive ordering of any set of values; otherwise the sort may never terminate. | You can define 'less', 'greater', and 'equal' in whatever way makes sense for you provided your definitions provide a definitive ordering of any set of values; otherwise the sort may never terminate. | ||
The optional third argument sorts the elements in reverse order. | The optional third argument sorts the elements in reverse order. | ||
===Notes=== | |||
*The returned array is always of type 'array'. | |||
*The original array may be of any type (array, map or stringmap). The original keys of map and stringmap arrays will be ignored. | |||
====Example==== | |||
In all three cases, the returned SortedArray will be exactly the same | |||
array_var as | |||
array_var ar | |||
array_var am | |||
array_var SortedArray | |||
let ar := ar_Construct array | |||
ar_Append ar 7 | |||
ar_Append ar 5 | |||
ar_Append ar 3 | |||
ar_Append ar 9 | |||
ar_Append ar 0 | |||
ar_Append ar 1 | |||
let SortedArray := ar_CustomSort ar zzCustomSort | |||
let am := ar_Construct map | |||
let am[1.1] := 7 | |||
let am[3] := 5 | |||
let am[4] := 3 | |||
let am[5.5] := 9 | |||
let am[6.6] := 0 | |||
let am[9] := 1 | |||
let SortedArray := ar_CustomSort am zzCustomSort | |||
let as := ar_Construct stringmap | |||
let as["A"] := 7 | |||
let as["B"] := 5 | |||
let as["C"] := 3 | |||
let as["D"] := 9 | |||
let as["E"] := 0 | |||
let as["F"] := 1 | |||
let SortedArray := ar_CustomSort as zzCustomSort | |||
scn zzCustomSort | |||
array_var ar1 | |||
array_var ar2 | |||
begin Function {ar1 ar2} | |||
if eval ar1[0] < ar2[0] | |||
SetFunctionValue 1 | |||
else | |||
SetFunctionValue 0 | |||
endif | |||
end | |||
| name = Ar_CustomSort | | name = Ar_CustomSort |