Difference between revisions of "Ar CustomSort"
no edit summary
imported>Odessa (Created page with "{{Function |origin = NVSE |summary = Sorts the elements of an array based on the return of a specified User Defined Function, which you must have previously created. A...") |
imported>Odessa |
||
Line 5: | Line 5: | ||
Ar_CustomSort will repeatedly take 2 elements from the array to sort, and pass them to the UDF as parameters in the form of two single element arrays. Your UDF determines how the values of the 2 array var parameters should be sorted in relation to each other. | Ar_CustomSort will repeatedly take 2 elements from the array to sort, and pass them to the UDF as parameters in the form of two single element arrays. Your UDF determines how the values of the 2 array var parameters should be sorted in relation to each other. | ||
This is useful if you wish to sort forms according to anything other than their name/formID (eg weight, size, skills etc), or sub-arrays. You let the function know that one element should be considered 'earlier than' or 'less than' in the resulting array's order by letting the UDF return 'true', ie: [[SetFunctionValue]]. | This is useful if you wish to sort forms according to anything other than their name/formID (eg weight, size, skills etc), or sub-arrays. You let the function know that one element should be considered 'earlier than' or 'less than' in the resulting array's order by letting the UDF return 'true', ie: [[SetFunctionValue]]. | ||
You can define the sorting method any way you like, but it must be definitive, otherwise an infinite loop (CTD) may result. | |||
|name = Ar_CustomSort | |name = Ar_CustomSort | ||
Line 14: | Line 16: | ||
|Name = ComparisonUDF | |Name = ComparisonUDF | ||
|Type = script}}{{FunctionArgument | |Type = script}}{{FunctionArgument | ||
|Name = <i> | |Name = <i>ReverseSort</i> | ||
|Type = <i>bool</i>}}}} | |Type = <i>bool</i>}}}} | ||
==Example== | ==Example== | ||
Line 62: | Line 64: | ||
</pre> | </pre> | ||
If the Ar_CustomSort function was called with the optional | If the Ar_CustomSort function was called with the optional ReverseSort boolean, it'll sort the array in reverse order, which in our case means in <i>ascending</i> order of medicine skill (due to implementation of the UDF): | ||
<pre> | <pre> | ||
0 GSJoeCobbRef | 0 GSJoeCobbRef |