LSL Wiki Mirror 10-5-2006: llListSort

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
list llListSort(list src, integer stride, integer ascending)

Sorts src into blocks of stride, in ascending order if ascending is TRUE, descending order if ascending is FALSE, and returns a new list. src is not changed.

Note that llListSort only works between items of the same type.

Setting stride to either 0 or 1 sorts each item in the list.

Strides


"strides" are groups of related data. For example, if you are storing information about vegetables, and you want to store the vegetable name, its color, and how many of them you have, you might have a list like this:

list vegetables = ["lettuce", "green", 20, "carrots", "orange", 11, "onions", "yellow", 0];

The stride for this list is 3, because there are 3 pieces of data in a block. llListSort sorts on the first bit of data in each block, in this case, the vegetable name. This command:

vegetables = llListSort(vegetables, 3, TRUE);

...returns this list:

["carrots", "orange", 11, "lettuce", "green", 20, "onions", "yellow", 0]

"carrots", "lettuce" and "onions" are now sorted into alphabetical order.

If data types do not match, llListSort still returns a modified list, but the results are unpredictable. Note that while the above example uses a list containing both strings and integers, because the stride is set to 3, llListSort only sorts the list according to the string containing the name of the vegetable.


Functions | Lists
There are 3 comments on this page. [Display comments/form]