Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dynamically add items to a list?

Barry Moody
Registered User
Join date: 17 Dec 2006
Posts: 24
10-16-2007 20:08
According to the LSL wiki; "A list can grow dynamically as large as needed during execution..."

Would be nice if they actually made some mention on that page as to HOW to do it.

I am used to something like - notifyAddresses[iMin] = data; - Where iMin is a global variable and data is a value from the dataserver event.

I assume there's something less straightforward to add an item to a list?
revochen Mayne
...says
Join date: 14 Nov 2006
Posts: 198
10-16-2007 20:15
To add an item to an existing list use this way:

listName += itemName;

greetings =)
Barry Moody
Registered User
Join date: 17 Dec 2006
Posts: 24
10-16-2007 20:17
Thanks!
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-16-2007 20:20
http://lslwiki.net/lslwiki/wakka.php?wakka=list

Whenever you manipulate a list, the simulator doubles it and that can cause you to run into a stack heap collision event.

The memory efficient way to add to a list and minimize that danger is like this:

myList = (myList=[]) + myList + ["new_item"];
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
10-16-2007 20:34
From: Jesse Barnett
myList = (myList=[]) + myList + ["new_item"];

Or, even more efficient..

myList = (myList = []) + myList + (list)"new_item";
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-16-2007 20:40
From: Sindy Tsure
Or, even more efficient..

myList = (myList = []) + myList + (list)"new_item";

OMG Can't believe I didn't catch that. Strife's "To add a single item, it saves on bytecode to cast it as a list instead of bracketing it" post!
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-17-2007 00:13
let me see if my head is wrapping around this properly....

set myList equal to...
the copied list cleared? (or is it the original list?) plus
the original list plus
the new item

seems a bit odd to be able to clear one copy before adding it back in...

then again it seems odd that they would copy the list to begin with

is there a better explanation of WHY this works?
::does not like voodoo coding, practices wants to know WHY::
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-17-2007 01:10
test..
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-17-2007 03:50
From: Void Singer

is there a better explanation of WHY this works?
::does not like voodoo coding, practices wants to know WHY::


"Our's is not to wonder why. Our's is to hack the crap out of it until we get what we want!"

God only know's why or how BlindWanderer came up with this work around. But person after person has tested and reseted the workaround out of curiosity, including myself to see that it really works. 3 to 4 kb is one heck of a lot when we are limited to only 16 kb to begin with.

Maybe Strife will pop in here and give a more detailed explanation of it's special magic.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
10-17-2007 04:03
Well, the LSL compiler source is available, so somebody with a bit of knowledge of parsers and code generation could probably figure it from the code.
_____________________