Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Replacing multiple sections of a list

Daisy Rimbaud
Registered User
Join date: 12 Oct 2006
Posts: 764
02-07-2007 16:02
I need to replace odd bits of a list that are not continuous. I would have thought that I could do this with multiple calls to llListReplaceList. So that say, I could take List1, and replace elements 1-3 with List2 and put the result in List3, then replace elements 7-9 of List3 and put the result in List4, but this doesn't seem to work. List4 is just an exact copy of List3.

What's the best way to do this, please?
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
02-07-2007 17:09
I don't think you can alter a list. The operation should produce a new list.
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
02-07-2007 17:14
list list3 = llListReplaceList(list1, list2 , 0, 2);
list list4 = llListReplaceList(list3, <you didn't offer a source list>, 6, 8);

or using fewer lists,

list replace1 = ["a", "b", "c"];
list replace2 = ["x", "y", "z"];
list1 = llListReplaceList(list1, replace1, 0, 2);
list1 = llListReplaceList(list1, replace2, 6, 8);
Daisy Rimbaud
Registered User
Join date: 12 Oct 2006
Posts: 764
02-07-2007 23:40
From: DoteDote Edison
list list3 = llListReplaceList(list1, list2 , 0, 2);
list list4 = llListReplaceList(list3, <you didn't offer a source list>, 6, 8);

or using fewer lists,

list replace1 = ["a", "b", "c"];
list replace2 = ["x", "y", "z"];
list1 = llListReplaceList(list1, replace1, 0, 2);
list1 = llListReplaceList(list1, replace2, 6, 8);


Ah, I see where I am misunderstanding. llListReplaceList replaces the part of the first list with the whole of the second. I was trying to replace elements 1-3 of a nine element list with elements 1-3 of a second nine-element list.
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
02-08-2007 16:01
Ah, in that case you could use llList2List() as the source, like this:

list LIST1 = ["A","B","C","D","E","F","G","H","I"];
list LIST2 = ["R","S","T","U","V","W","X","Y","Z"];

LIST1 = llListReplaceList(LIST1, llList2List(LIST2, 0, 2), 0, 2);
// returns: ["R","S","T","D","E","F","G","H","I"];

then,
LIST1 = llListReplaceList(LIST1, llList2List(LIST2, 6, 8), 6, 8);
// returns: ["R","S","T","D","E","F","X","Y","Z"];
Daisy Rimbaud
Registered User
Join date: 12 Oct 2006
Posts: 764
02-09-2007 07:56
From: DoteDote Edison
Ah, in that case you could use llList2List() as the source, like this:

list LIST1 = ["A","B","C","D","E","F","G","H","I"];
list LIST2 = ["R","S","T","U","V","W","X","Y","Z"];

LIST1 = llListReplaceList(LIST1, llList2List(LIST2, 0, 2), 0, 2);
// returns: ["R","S","T","D","E","F","G","H","I"];

then,
LIST1 = llListReplaceList(LIST1, llList2List(LIST2, 6, 8), 6, 8);
// returns: ["R","S","T","D","E","F","X","Y","Z"];


That's clever!

However, I opted for a series of one-item lists and then used llListReplaceList to replace single elements at a time. In the context, it's actually clearer than keeping all the replacement elements in a single list, as the single-element lists have meaningful names for the functions they play.