Difference between revisions of "LlListInsertList"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{LSL_Function/negative index|true|start}}{{LSL_Function
{{LSL_Function
|inject-2=
 
{{#vardefine:spec_between|If {{LSLP|start}} is past the end of {{LSLP|dest}}, then {{LSLP|src}} is appended to {{LSLP|dest}}, it will not add null entries.  To avoid this, create empty elements in the list first. A similar outcome occurs when using {{LSLGC|Negative Index|negative indexes}}.}}
 
{{LSL_Function/negative index|true|start}}
 
|func_id=200|func_sleep=0.0|func_energy=10.0
|func_id=200|func_sleep=0.0|func_energy=10.0
|func=llListInsertList|return_type=list|p1_type=list|p1_name=dest|p2_type=list|p2_name=src|p3_type=integer|p3_name=start
|func=llListInsertList
|return_type=list
|p1_type=list|p1_name=dest
|p2_type=list|p2_name=src
|p3_type=integer|p3_name=start
|func_footnote
|func_footnote
|func_desc
|func_desc
|return_text=that is '''src''' inserted into '''dest''' at position '''start'''.
|return_text=that contains all the elements from {{LSLP|dest}} but with the elements from {{LSLP|src}} inserted at position {{LSLP|start}}.
|spec
|spec
|caveats
|caveats
|constants
|constants
|examples
|examples=
<source lang="lsl2">
list numbers = [3, "three", 2, "two", 1, "one"];
default
{
    state_entry()
    {
        llOwnerSay(llDumpList2String(numbers, ","));
        // Object: 3,three,2,two,1,one
        integer index = llListFindList(numbers, [2]);
        if (index != -1)
        {
            numbers = llListInsertList(numbers, [2.5, "two and a half"], index);
            llOwnerSay(llDumpList2String(numbers, ","));
            // Object: 3,three,2.500000,two and a half,2,two,1,one
        }
    }
}
</source>
|helpers
|helpers
|also_functions=*{{LSLG|llDeleteSubList}}
|also_functions={{LSL DefineRow|[[llDeleteSubList]]}}
*{{LSLG|llList2List}}
{{LSL DefineRow|[[llList2List]]}}
*{{LSLG|llListReplaceList}}
{{LSL DefineRow|[[llListReplaceList]]}}
|also_events
|also_events
|also_tests
|also_tests
|also_articles
|also_articles
|notes
|notes=
Bear in mind that the source list will remain unchanged. Instead, a new list will be produced. So, it's important that you capture this with a variable (unless you are acting directly on the results.)
 
 
Tip! To insert something at the start of a list, you can just add the two lists (putting the list with the new item(s) first)
 
<source lang="lsl2">
list oldList = ["B", "C", "D"];
list newItem = ["A"];
list newlist = newItem + oldList;
</source>
 
|permission
|permission
|sort=ListInsertList
|sort=ListInsertList

Latest revision as of 12:15, 22 January 2015

Summary

Function: list llListInsertList( list dest, list src, integer start );

Returns a list that contains all the elements from dest but with the elements from src inserted at position start.

• list dest
• list src
• integer start

start supports negative indexes.

Specification

Index Positive Negative
First 0 -length
Last length - 1 -1

Indexes

  • Positive indexes count from the beginning, the first item being indexed as 0, the last as (length - 1).
  • Negative indexes count from the far end, the first item being indexed as -length, the last as -1.

Caveats

  • If start is out of bounds the script continues to execute without an error message.
All Issues ~ Search JIRA for related Bugs

Examples

list numbers = [3, "three", 2, "two", 1, "one"];
default
{
    state_entry()
    {
        llOwnerSay(llDumpList2String(numbers, ","));
        // Object: 3,three,2,two,1,one
        integer index = llListFindList(numbers, [2]);
        if (index != -1)
        {
            numbers = llListInsertList(numbers, [2.5, "two and a half"], index);
            llOwnerSay(llDumpList2String(numbers, ","));
            // Object: 3,three,2.500000,two and a half,2,two,1,one
        }
    }
}

Notes

Bear in mind that the source list will remain unchanged. Instead, a new list will be produced. So, it's important that you capture this with a variable (unless you are acting directly on the results.)


Tip! To insert something at the start of a list, you can just add the two lists (putting the list with the new item(s) first)

list oldList = ["B", "C", "D"];
list newItem = ["A"];
list newlist = newItem + oldList;

See Also

Functions

• llDeleteSubList
• llList2List
• llListReplaceList

Articles

•  Negative Index

Deep Notes

Search JIRA for related Issues

Signature

function list llListInsertList( list dest, list src, integer start );