Don't click here unless you want to be banned.

LSL Wiki : llListSort

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl809.us.archive.org
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. If ascending is not equal to TRUE then it is considered FALSE (not typical in LSL).

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

Setting stride to either 0 or 1 sorts each item in the list. For any other number, if the length of src is not a multiple of stride this function will silently fail.

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 strange. 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.

I've been doing a bit of research into this function and here is how it sorts mixed lists. It sorts the list by each type, then it recombines the sorted result by type, so if the first position was a key, then in the output the first position is a key. So...
llListSort([3, "a",1,"c", 2, "b"], 1, TRUE) --> [1, "a", 2, "b", 3, "c"]
I am having problems imagining how this could be useful. -- BW
Ans: This example is using a stride of 1: use a stride of 2 and it will sort the list in a useful way.


Using a stride of 2 in the example above, the result would be:-- KW
llListsort([3, "a", 1, "c", 2, "b"], 2, TRUE) -->  [1, "c", 2, "b", 3, "a"]


This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | Lists
Comments [Hide comments/form]
The documentation doesn't explicity say it, but setting ascending == FALSE does sort the list in descending order.
-- GunzourYellowknife (2004-06-26 22:31:49)
"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", 5, "carrots", "orange", 73, "onions", "yellow", 0];

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

vegetables = llListSort(vegetables, 3, TRUE);

will return this list:

["carrots", "orange", 73, "lettuce", "green", 5, "onions", "yellow", 0 ]
-- GunzourYellowknife (2004-06-26 22:40:12)
If data types do not match, llListSort still returns a modified list, but as far as I can tell the results are unpredictable.

To sort a basic list with no strides, use a value of 0 for stride.
-- GunzourYellowknife (2004-06-26 22:42:27)
Attach a comment to this page: