llListFindStrided
integer llListFindStrided(list ListVariable, list Find, integer Start, integer End, integer Stride)Returns the index of the first instance of Find in ListVariable. Returns -1 if not found.
Returns the position of the first instance of the Find list in the ListVariable after the start index and before the end index. Steps through ListVariable by stride. Returns -1 if not found.
Parameters
-
ListVariable(list) -
Find(list) -
Start(integer) -
End(integer) -
Stride(integer)
- Strict type matching and case sensitivity is enforced:
"1"!=1"1.0"!=1.01!=1.0"a822ff2b-ff02-461d-b45d-dcd10a2de0c2"!=(key)"a822ff2b-ff02-461d-b45d-dcd10a2de0c2""Justice"!="justice"
- If
testis an empty list[], the value returned is0rather than-1 - If
testis not found insrc,-1is returned - The length of
testmay be equal to or less thanstridein order to generate a match - The index of the first entry in the list is 0
- If
testis found at the last index insrc, the positive index is returned (5th entry of 5 returns 4) - If
startorendis negative, it is counted from the end of the list (the last element is -1, the first is -list_length)
Examples
Section titled “Examples”Basic Search with Stride 1
Section titled “Basic Search with Stride 1”list mylist = ["a", 0, "b", 1, "c", 2, "b", 1];
integer result_a = llListFindStrided(mylist, ["b"], 0, -1, 1);// result_a = 2 (functionally equivalent to llListFindList)
integer result_b = llListFindStrided(mylist, ["b", 1], 2, -1, 1);// result_b = 2 (find pattern at index 2)
integer result_c = llListFindStrided(mylist, ["b"], 3, -1, 1);// result_c = 6 (first "b" at index 2 is skipped by starting at 3)Using Different Strides
Section titled “Using Different Strides”list mylist = ["a", 0, "b", 1, "c", 2, "b", 1];
integer result_h = llListFindStrided(mylist, ["c"], 0, -1, 2);// result_h = 4 (with stride of 2, "c" is found at index 4)
integer result_i = llListFindStrided(mylist, ["c"], 0, -1, 3);// result_i = -1 (with stride of 3, "c" is not found)
integer result_j = llListFindStrided(mylist, ["c"], 0, -1, 4);// result_j = 4 (with stride of 4, "c" is found at index 4)Finding Elements in a List
Section titled “Finding Elements in a List”list numbers = [1, 2, 3, 4, 5];
default { state_entry() { integer index = llListFindStrided(numbers, [3], 0, -1, 1); if (index != -1) { list three_four = llList2List(numbers, index, index + 1); llOwnerSay(llDumpList2String(three_four, ",")); // Output: 3,4 } }}Searching for Patterns
Section titled “Searching for Patterns”// Search for two items at once to find a pattern in a listlist avatarsWhoFoundMagicLeaves = ["Water Duck", "Green Ham", "Fire Centaur", "Red Leaf"];
default { state_entry() { integer index = llListFindStrided(avatarsWhoFoundMagicLeaves, ["Fire Centaur", "Red Leaf"], 0, -1, 2); if (index != -1) { list output = llList2List(avatarsWhoFoundMagicLeaves, index, index + 1); llOwnerSay(llDumpList2String(output, ",")); // Output: Fire Centaur,Red Leaf } }}Database-like Search
Section titled “Database-like Search”// Using stride to search like a databaselist food_db = ["FIRSTNAME", "LASTNAME", "FAVORITE FOOD", "ALLERGIES", "Awesome", "Resident", "Apples", 0, "Charlie", "Kites", "Peanuts", "dogs", "Cool", "McLastname", "Burgers", "peanuts"];
default { state_entry() { list potential_allergen = ["peanuts"]; integer any_allergies = llListFindStrided(food_db, potential_allergen, 4, -1, 4); if (any_allergies != -1) { llOwnerSay("Everyone can eat it"); } else { list output = llList2List(food_db, any_allergies - 3, any_allergies - 2); llOwnerSay(llDumpList2String(output, " ") + " is allergic to it!"); } }}See Also
Section titled “See Also”- llSubStringIndex - Find a string in another string
- llListFindList - Find elements in a list