Jump to content

generating variable names -- noob alert

Rhiannon Arkin

You are about to reply to a thread that has been inactive for 2663 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts


Ok. this is embarrasing but i can't figure out how to do this:


i have 3 global lists i want to add information to (quest1, quest2, quest3)

looks like a job for a loop,


string nameOfList = "quest"+((string)counter) is resulting in  "quest1" . fine. 

now this is the name for the list i want to use BUT

l = llGetListLength(nameOfList) .... doesn't work as it projects the content of nameOfList and not the list called nameOfList.

and the same problem on the other side of the =

nameOfList += "blabla" ;

clearly doesn't work because nameOfList is not the list itself but only it's name in form of a string variable. 

I couldn't find an example anywhere so I have to ask here, how can I generate the names of existing lists so i can use them in all sorts of loops? 

any thoughts about this ??





Link to comment
Share on other sites

I don't really understand the question because the logic of your script isn't entirely clear from the description you give.

On the face of it, it looks as if your problem can be solved by something like 

		if(1 == counter){			quest1 +=[strInput];		}		else if (2 == counter){			quest2 +=[strInput];		}		else if (3 == counter){			quest3 +=[strInput];		}

but I suspect there is  more to the problem than is apparent from what you've said.

Have you considered using a single, strided, list?   


Link to comment
Share on other sites

you could try json and use json objects or json arrays...

something like....

string info;
string name;
string GuestMain;

key avKey;

         info = llList2Json (JSON_OBJECT, [
         "AVkey", JSON_NULL ] );
         GuestMain = llList2Json( JSON_OBJECT, [] );


and somewhere in your code have something like...

 name = llDetectedName(0); // (or guest1, guest2, etc)

 avKey = llDetectedKey(0); // or whatever...

if (llJsonGetValue (GuestMain, [name] ) == JSON_INVALID)
                     GuestMain = llJsonSetValue (GuestMain, [name], info);
                     GuestMain = llJsonSetValue (GuestMain, [name,  "AVkey"], avKey);                    

list details =  llJson2List ( GuestMain );

details = llList2ListStrided(details,0,-1,2);  // gives the strided list of names


OR just put all the info in a regular strided list...

list GuestMain;

GuestMain += "guest1";

GuestMain += "key1";

GuestMain += "guest2";

GuestMain += "key2";


etc etc

Link to comment
Share on other sites

Rhiannon Arkin wrote:

Even more generic so that even the quest1,2,3 are result of a formula. 

I am looking into stridend lists too.  

If the three lists represent a list of triples (that is, the k-th element of quest1 corresponds to the k-th elements of quest2 and quest3 such that you'll iterate through those lists in lockstep) then a 3-strided list is probably the best you can do. That nicely generalizes to n-strided lists for any n-tuples. (If the contents are only numbers, artificially representing them as vectors or rotations is a storage efficiency hack.)

The practice of referencing variable names as data is much more common in interpreted languages because compilers usually strip out variable names after resolving references to them in the code. In contrast, an intrepreter can "evaluate" data at runtime to resolve symbols as variables, function names, and even in some "dynamic" languages whole new data types.

In LSL, the "general" ways of doing such things make the symbol strictly data instead of a variable name. There are all sorts of ways to do that. JSON is one way. Alternatively, scripts can maintain a list of symbols, offsets, and perhaps lengths, as a dynamic index into a long flat list of values.

The Key-Value Pair structure of Experience persistent store is another relevant representation for scripts that can use Experiences. It lets a script use a "Key" symbol to reference arbitrarily structured Values, so the "Key" is conceptually similar to a variable name symbol -- but access is asynchronous, in exchange for practically unlimited capacity.

Link to comment
Share on other sites

in essence I'm just storing a list of questions in each of the lists. the questions come from three notecards. 

I want to use globals because reading questions from notecards seems to lag more. 

So the basic solution of usign 'if' for the three cases is working fine. 

I find the suggested json lists interesting, but need to read into this. as right now i have no idea what the json thing really is. 


Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2663 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...