Difference between revisions of "LlListFindList"

From Second Life Wiki
Jump to navigation Jump to search
m (Remove sort=... from LSL_Function template - was being sorted under 't')
Line 1: Line 1:
{{LSL_Function
{{Issues/SVC-5146}}{{LSL_Function
|func=llListFindList
|func=llListFindList
|func_id=201|func_sleep=0.0|func_energy=10.0
|func_id=201|func_sleep=0.0|func_energy=10.0

Revision as of 04:29, 7 October 2010

Summary

Function: integer llListFindList( list src, list test );

Returns an integer that is the index of the first instance of test in src.

• list src
• list test

If test is not found in src, -1 is returned.
The index of the first entry in the list is 0
If test is found at the last index in src the positive index is returned (5th entry of 5 returns 4).

Caveats

  • Strict type matching and case sensitivity is enforced.
  • if (test == []), return = 0 rather than -1.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl>list numbers = [1, 2, 3, 4, 5]; default {

   state_entry()
   {
       integer index = llListFindList(numbers, [3]);
       if (index != -1)
       {
           list three_four = llList2List(numbers, index, index + 1);
           llOwnerSay(llDumpList2String(three_four, ","));
           // Object: 3,4
       }
   }

}</lsl><lsl>//You can also search for two items at once to find a pattern in a list list avatarsWhoFoundMagicLeaves = ["Fire Centaur","Red Leaf"]; default {

   state_entry()
   {
       integer index = llListFindList(avatarsWhoFoundMagicLeaves, ["Fire Centaur","Red Leaf"]);
       if (index != -1)
       {
           list output = llList2List(avatarsWhoFoundMagicLeaves, index, index + 1);
           llOwnerSay(llDumpList2String(output, ","));
           // Object: Fire Centaur, Red Leaf
       }
   }
}</lsl>

Useful Snippets

An easy way to see if an item exists in a list... <lsl>if(~llListFindList(myList, (list)item)) {//it exists

   //This works because ~(-1) == 0
   //It saves bytecode and is faster then doing != -1

}</lsl>

See Also

Functions

•  llSubStringIndex Find a string in another string
•  List: Find Last Index Returns an integer that is the index of the last instance of test in src.
•  List: Multi-Find Index (First_or_Last) Get first(or last) Index of any matching elements of test in src.

Deep Notes

All Issues

~ Search JIRA for related Issues
   llSortedListFindList() - improved llListFindList() for known to be sorted lists

Signature

function integer llListFindList( list src, list test );