Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Lists

Nicola Mondrian
Registered User
Join date: 10 Jun 2005
Posts: 11
07-28-2005 05:13
Hi!
I read the lsl wiki entries for lists and know how to create a list but I seem to be too stupid to figure out how to save something into a certain field of a list (something like 'listvariable[0]="1";').
Is it impossible to access lists like that?
I know you can do 'newlist=oldlist + ["x","xx"]; '
but that does not really help me.


NM
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
07-28-2005 05:19
Lists don't work like that, I'm afraid.

You would have to write your own routines to be able to act on list elements in that fashion.

Think of a list not as a single dimensional array of variables ('cause it isn't) but as a line of static data elements.

The wiki has a section listing all the library calls that act on lists. Hopefully a combination of these will get you what you're looking for.
_____________________
Nicola Mondrian
Registered User
Join date: 10 Jun 2005
Posts: 11
07-28-2005 05:46
Thank you, I will look at the link.
But does that mean lsl does not have arrays at all?

NM
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
07-28-2005 05:49
From: Nicola Mondrian
But does that mean lsl does not have arrays at all?
That, I am sorry to say, is the case. LSL doesn't have anything resembling an array.
_____________________
Nicola Mondrian
Registered User
Join date: 10 Jun 2005
Posts: 11
07-28-2005 05:54
Awwww :(

Thanks :)


NM
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
07-28-2005 06:03
I've not scripted it at all, but you should be able to insert an item at a specific point.

You create a temporary list of everything before that point in the old list llList2List() , add your new item, then add the rest of the old list, then replace the old list with the temporary one.

Removing a specific item works similarly, you copy everything before and everything after the item you want removing.

Of course that might not do precisely what you're after depending on what cleverness you have in mind, but it will duplicate the insert to a specific point that you asked about.
Jon Marlin
Builder, Coder, RL & SL
Join date: 10 Mar 2005
Posts: 297
07-28-2005 06:44
You can use llListReplaceList to accomplish what you are trying to do...

CODE

list MyList = ["One", "To", "Three"];
MyList = llListReplaceList (MyList, ["Two"], 1, 1);


This allows you to replace one or more elements of a list with a different list. Note that this function is not destructive -- it does not modify the original, rather it returns the new list, which you can (optionally) assign back to the original variable...

- Jon
_____________________
Come visit Marlin Engineering at Horseshoe (222, 26) to see my line of flying vehicles.
Zeno Concord
To infinity, and beyond!
Join date: 28 Mar 2005
Posts: 51
Lists are mutable - yes like variables
07-28-2005 06:46
From: Eloise Pasteur
You create a temporary list of everything before that point in the old list llList2List() , add your new item, then add the rest of the old list, then replace the old list with the temporary one.

It is easier than that reconstructive surgery. Try llListInsertList() and llListReplaceList(). You can also replace with a longer or shorter sublist, so deletion is possible.

The notation is very awkward for the equivalent of myArray[2] = whatever. But oh well.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
07-28-2005 09:55
Ah, I'd forgotten they bought ListReplaceList in, and the last time I was doing this big time was pre that date, 1.6.? thank you though.