Difference between revisions of "LlListFindList"
Jump to navigation
Jump to search
Void Singer (talk | contribs) m (added "List: Find Last Index" and "List: Multi-Find Index" to also functions.) |
(added info clarifying the return of the last (if found) index not being -1) |
||
Line 5: | Line 5: | ||
|return_type=integer|p1_type=list|p1_name=src|p2_type=list|p2_name=test | |return_type=integer|p1_type=list|p1_name=src|p2_type=list|p2_name=test | ||
|func_footnote=If '''test''' is not found in '''src''', {{HoverText|-1|negative one, 0x{{LSL_Hex/Write|-1}}}} is returned.<br/> | |func_footnote=If '''test''' is not found in '''src''', {{HoverText|-1|negative one, 0x{{LSL_Hex/Write|-1}}}} is returned.<br/> | ||
The index of the first entry in the list is {{HoverText|0|zero}} | The index of the first entry in the list is {{HoverText|0|zero}}<br> | ||
If '''test''' is found at the last index in '''src''' the positive index is returned (5th entry of 5 returns 4). | |||
|func_desc | |func_desc | ||
|return_text=that is the index of the first instance of '''test''' in '''src'''. | |return_text=that is the index of the first instance of '''test''' in '''src'''. |
Revision as of 06:44, 17 August 2009
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: integer llListFindList( list src, list test );201 | Function ID |
0.0 | Forced Delay |
10.0 | Energy |
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
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>
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. |