llList2ListSlice
list llList2ListSlice(list ListVariable, integer Start, integer End, integer Stride, integer slice_index)Returns a subset of entries from ListVariable, in a range specified by Start and End indices (inclusive) return the slice_index element of each stride.
Using negative numbers for Start and/or End causes the index to count backwards from the length of the list. (e.g. 0, -1 captures entire list)
If slice_index is less than 0, it is counted backwards from the end of the stride.
Stride must be a positive integer > 0 or an empy list is returned. If slice_index falls outside range of stride, an empty list is returned. slice_index is zero-based. (e.g. A stride of 2 has valid indices 0,1)
Parameters
-
ListVariable(list) -
Start(integer) -
End(integer) -
Stride(integer) -
slice_index(integer)
Basic Stride Slicing
Section titled “Basic Stride Slicing”list mylist = [0,1,2,3,4,5,6];list result_a = llList2ListSlice(mylist, 0, -1, 3, 0);//result_a == [0,3,6]
list result_b = llList2ListSlice(mylist, 0, -1, 3, 1);//result_b == [1,4]
list result_c = llList2ListSlice(mylist, 1, -1, 3, 1);//result_c == [2,5]
list result_d = llList2ListSlice(mylist, 2, -1, 3, -1);//result_d == [4]
list result_e = llList2ListSlice(mylist, 4, 2, 1, 0);//result_e == [0,1,2,4,5,6]Dialog Menu Builder
Section titled “Dialog Menu Builder”list menu = ["1", "one", "2", "two", "3", "three"];default{ state_entry() { llListen(10, "", llGetOwner(), ""); } touch_start(integer detected) { list buttons = llList2ListSlice(menu, 0, -1, 2, 0); llDialog(llDetectedKey(0), "choose a number", buttons, 10); //display the digits } listen(integer channel, string obj, key id, string message) { integer index = llListFindList(menu, [message]); if (index != -1) { list names = llList2ListSlice(menu, 0, -1, 2, 1); llOwnerSay("you chose " + llList2String(names, index/2) + " (" + message + ")"); } }}- Negative Indices: Start, end, or slice_index can be negative to count from the end of the list. -1 is the last element, -list_length is the first element.
- Negative slice_index: When negative, it counts from the end of its stride (e.g., -1 is the last element in a stride), regardless of whether the stride exceeds the list length.
- Exclusion Range: If start > end, the range is treated as an exclusion range, returning all elements outside that range.
- Incomplete Strides: If the list is not modulo the stride, elements up to the list length will be returned in the final slice matching conditions. For example, a 5-element list with stride 2 returns 3 elements for range 0-5 on slice_index 0, but only 2 elements if slice_index is 1.
- Helper Function: See
StrideOfListin User:Fred_Gandt/Scripts/Functions for working with strided lists.