Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Manipulating the name of a list?

Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
05-23-2006 03:12
I have a series of lists that I want to use sequentially in a script, and I will be adding more lists later so I'm trying to see if I can "increment" the name of a list by treating it as a string, appending a character at the end, and passing it as the new name of the list.

Pseudocode:
CODE

list mylist0 = [foo,foo,foo,foo,foo];
list mylist1 = [bar,bar,bar,bar,bar];
list mylist2 = [foo,bar,foo,bar,foo];
integer num_lists = 3;

then
CODE

for (loop = 0; loop < num_lists; loop++)
{
currentlist = ("mylist"+(string)loop);
do stuff with (llList2CVS(currentlist));
}

A function like llList2CVS expects the name of a list, and complains when I feed it a string even if it *looks* just like the name of a list. Anybody see a way around this? Or a different approach that I can't see?

Thanks.
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
05-23-2006 03:38
No, you can't do that, sorry.
Jigsaw Partridge
A man of parts
Join date: 3 Apr 2005
Posts: 69
05-23-2006 03:53
One approach would be to put all your lists into one big list, and maintain (in another list, possibly) the start index of each of these sublists. I tend to use this approach a lot when reading lines from a notecard. If every sublist has the same number of elements, then it is even easier, since you can just calculate the start index of each sublist in it.

Edit: Forgot to mention, in case it wasn't clear, you can then just pass llList2List(), with appropriate start/end index arguments, to llList2CVS() in each loop iteration.
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
05-23-2006 04:57
From: Anti Antonelli
Or a different approach that I can't see?

Strided list, but you are likely to run into memory shortage this way.

Alternatively, put each of the lists into separate, linked prim. In the main script you can have a small list that maps list number -> link number, and use linked messages to communicate with your lists....

(or yet alternatively, use multiple list scripts in the same prim, with each script having its own assigned id and responding only when message is sent to 'it' ... indicated with integer in the sent message, or whatever)
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
05-23-2006 05:27
Thanks to all of you.

What I wasn't clear about is that I'm working on an ongoing, evolving project and I'm trying to simplify matters as I add lists down the road (and I had been considering a saleable item with permissions such that the end user could add additional lists as required). The reason I wanted to try and manipulate list names and refer to them indirectly is one of housekeeping, making the thing as easily modifiable as possible without the need to really get into the guts of the script and edit every function that calls the lists.

I guess my limited background with simple procedural "languages" like DOS/Windows batch stuff has me in the habit of thinking that strings and labels and such can be parsed and tortured and cast any way at all without regard for what they really are, and that isn't the case in "real" languages. Not a huge deal, I'll adjust my goals and move on. :)
Gigs Taggart
The Invisible Hand
Join date: 12 Feb 2006
Posts: 406
05-23-2006 11:07
From: Anti Antonelli
that isn't the case in "real" languages. Not a huge deal, I'll adjust my goals and move on. :)


Most real languages can indeed do this. PHP has variable variables, C has pointers, Java has references... as you noticed even batch and shell scripts can do it.

But LSL doesn't offer any sort of indirection. It is very frustrating when trying to construct anything but the most simple data structures.

I think it's an artifact of being a completely by-value language. Just something we all have to work around, for a long while at least.
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
05-23-2006 12:26
From: Gigs Taggart
Most real languages can indeed do this. - snip! -

Thanks for the comments. Not being a coder at all, I had come to the conclusion that I was ignorantly asking for something ridiculous. It's nice to know that there wasn't anything inherently stupid about my idea (even if the implementation I had in mind left a lot to be desired).
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
05-23-2006 12:36
Not a sensible idea for this purpose, but this kind of thing does work for rezzing objects from inventory. You can call llRezObject("object"+(string)num, ....);
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Jigsaw Partridge
A man of parts
Join date: 3 Apr 2005
Posts: 69
05-23-2006 21:48
Well, you could argue that for any language, even if a particular 'feature' isn't implemented, it is always possible to emulate it at the application level. For example, in your case my understanding is that what you are after is a way of creating arbitrarily 'named' lists at runtime, and then retrieving these (by name), editing them, passing them to LSL library functions, deleting them etc.

So, you could just create two native LSL lists - one containing all of your 'sub-lists', as described previously, the other being a simple strided list containing (for each currently-defined named list) the name, the start index, and the number of elements. All you would need to implement then would be a few utility functions - create named list, delete named list, retrieve named list, edit named list etc.

Of course, the question of whether this is worth the effort or not is debatable! It depends really on how often you would be likely to find such a facility useful in other scripts.