Don't click here unless you want to be banned.

LSL Wiki : llListReplaceList

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl427.us.archive.org
list llListReplaceList(list dest, list src, integer start, integer end)

Returns a list replacing the slice of the list dest from start to end with the list src. start and end are inclusive, so 0, 1 would replace the first two entries and 0, 0 would replace only the first list entry.

Using negative numbers for start and/or end causes the index to count backwards from the length of the list, so 0, -1 would replace the entire list.

If start is larger than end, the list returned is the list between start and end followed by src, so 6, 4 would return the 5th entry with src after that.

Example of Slices:
// (Note that this is not real code.)
list    foo = ["a", "b", "c", "d", "e", "f", "g"];
list    bar = ["0", "1"];
list    zot;
zot = llListReplaceList(foo, bar, 2, 5); // returns ["a", "b", "0", "1", "g"]
zot = llListReplaceList(foo, bar, 4, -1); // returns ["a", "b", "c", "d", "0", "1"]
zot = llListReplaceList(foo, bar, 4, 1); // returns ["c", "d", "0", "1"]

Note:
llListReplaceList does not manipulate dest directly. The list returned by this function is the modified version of the dest. See the following example:

Functional Example:
default {
    touch_start(integer total_number) {
        list foo = ["a", "b", "c", "d", "e", "f", "g"];
        list bar = ["0", "1"];
        foo = llListReplaceList(foo, bar, 2, 5); // to really return ["a", "b", "0", "1", "g"]
        // or done with the list hack
        foo = (foo=[]) + llListReplaceList(foo, bar, 2, 5); // to really return ["a", "b", "0", "1", "g"]
        llOwnerSay(llList2CSV(foo));
    }
}

To replace a stride in the list:
list UpdateSubListStrided(list src, list stride, integer start, integer stride_len) {
    return llListReplaceList(src, stride, start, start + stride_len - 1);
}

Question: Does the slice definied by start and end need to be the same length as src?
Answer: No, you can replace a slice with a longer or smaller src.

Question: I don't get it. It's not replacing my list.
Answer: No, llListReplaceList doesn't actually manipulate dest directly, rather it returns a new list containing the results. To manipulate a list directly, you need to do something like the functional example above. Alternatively, you can pass the result to a new list, and keep the original the same.

Compare with llList2List, llList2ListStrided, llListInsertList, llDeleteSubList, llList2Float, llList2Integer, llList2Key, llList2Rot, llList2String and llList2Vector.


This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | Lists
Comments [Hide comments/form]
the examples above don't really work because of the subtil note: "This function does not manipulate dest directly. The list returned by this function is the modified version of the dest."

default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
    }

    touch_start(integer total_number)
    {
        list foo = ["a", "b", "c", "d", "e", "f", "g"];
        list bar = ["0", "1"];
        foo = llListReplaceList(foo, bar, 2, 5); // to really return ["a", "b", "0", "1", "g"]
        llOwnerSay(llList2CSV(foo));
    }
}
-- NonnuxWhite (2005-07-03 04:41:27)
Not sure what you are talking about. This seems fine to me.
-- JippenFaddoul (2006-08-30 19:38:42)
A little confused here. This says "0, 1 would replace the entire list." Wouldn't 0,1 just replace the first two elements of the list?
-- JamalMfume (2006-10-02 04:32:31)
I corrected that. It would be entire list if the list only contained 2 entries. It now reads 0, 1 will replace only first two entries
-- AakanaarLaSalle (2006-10-02 13:50:45)
Am I right, that passing a list bigger than 8K (half of the script free memory) and modyfying it slightly enough to not impact result size, will trigger a stack/heap collision?
Which greatly reduces usability of this function to manipulate lists as data storage devices...?
-- TobasDryke (2007-07-03 02:59:57)
Is memory that is no longer accessible released for future use (garbage collect?) or is it simply wasted?
-- HeusDens (2007-08-01 20:08:37)
Attach a comment to this page: