Difference between revisions of "LlListFindList"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 5: Line 5:
|return_type=integer
|return_type=integer
|Return_text=index of the first instance of {{LSLP|test}} in {{LSLP|src}}.
|Return_text=index of the first instance of {{LSLP|test}} in {{LSLP|src}}.
|p1_type=list|p1_name=src|p1_desc=list to search in (haystack)
|p1_type=list|p1_name=src|p1_desc=what to search in (haystack)
|p2_type=list|p2_name=test|p2_desc=list to search for (needle)
|p2_type=list|p2_name=test|p2_desc=what to search for (needle)
|func_footnote=If {{LSLP|test}} is not found in {{LSLP|src}}, {{LSL Const|ERR_GENERIC|integer|ihex=-1}} is returned.<br/>
|func_footnote=If {{LSLP|test}} is not found in {{LSLP|src}}, {{LSL Const|ERR_GENERIC|integer|ihex=-1}} is returned.<br/>
The index of the first entry in the list is {{HoverText|0|zero}}<br>
The index of the first entry in the list is {{HoverText|0|zero}}<br>

Revision as of 15:17, 12 September 2013

Summary

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

Returns the integer index of the first instance of test in src.

• list src what to search in (haystack)
• list test what to search for (needle)

If test is not found in src, ERR_GENERIC 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.
    • "1" != 1
    • "1.0" != 1.0
    • 1 != 1.0
    • "a822ff2b-ff02-461d-b45d-dcd10a2de0c2" != (key)"a822ff2b-ff02-461d-b45d-dcd10a2de0c2"
    • "Justice" != "justice"
  • If test is an empty list the value returned is 0 rather than ERR_GENERIC.
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
   //This is a bitwise NOT (~) not a negation (-)

}</lsl>

See Also

Functions

•  llSubStringIndex Find a string in another string

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 );