SortBy
This formula allows you to sort an array (list) of values.
JSON Format
{
"type": "sortBy",
"components": ...,
"sort_by_selector": ...,
"order": ...,
"sort_by_value_key": ...
}
Fields
| Field | Type | Required | Description |
|---|---|---|---|
components | StatFormulaComponent | ✓ | The formula for the array (list) of elements you want to sort. |
sort_by_selector | StatFormulaComponent | ✓ | The formula for the selector that should be used to perform the sort. This selector allows you to choose a substat (if applicable) to perform the sort on. For example, if you have a list of spells and you want to sort by level, you would have the selector be: json { "type": "stat", "stat": "$sortByValue.level" } If you wanted to just sort by the value itself, you can always just write: json { "type": "stat", "stat": "$sortByValue" } Eligible selector values must be either strings or numbers, and they should all be of the same type. Anything inside this formula can make use of the $sortByValue stat, which will contain the current value for the iteration (e.g: if iterating the array ['a', 'b', 'c'], $sortByValue will first be equal to 'a', then 'b' and then 'c'), thus allowing the formula specified here to access the value of each element in the array one at a time as part of the selector. If you were to specify the optional sort_by_value_key parameter, you should use the key given there instead of $sortByValue to access these values. |
order | SortByOrder | ✓ | The sort order to utilize. |
sort_by_value_key | String | Optional parameter that lets you provide a key to use in the sort_by_selector formula to access the array's current value in the iteration. e.g: if you are iterating classes, you might want to assign "$class" to the sort_by_value_key, to make your system easier to read. This is also helpful when dealing with nested SortBy formulas, as it will allow inner SortBy formulas to access the values of outer filter formulas. |