Jump to content

Is it possible to call a list using incoming data strings or integers?


Beowulf Zessinthal
 Share

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

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

Recommended Posts

here is my failed example.. im guessing its not possible but will be delighted to be shown the way!

thanks for info^^

default
{
    state_entry(){
    list listnumber1= [1,2,3];
    list listnumber2= [4,5,6];
        
//    string which= "2";  llOwnerSay( llDumpList2String( (list) ("listnumber"+which) , ", ") );
//    string which= "2";  llOwnerSay( llDumpList2String( (list) "listnumber"+which , ", ") );
    string which= "listnumber2";    llOwnerSay( llDumpList2String( (list)which , ", ") );
    }
}

 

Link to comment
Share on other sites

You're quite right.  That won't work.  In LSL, you cannot use a variable name as a value for another variable, or vice versa.  The best you can do is set up a stack of if tests:

 

integer i = (integer) message;if (i == 1){    llOwnerSay(llList2CSV(listnumber1));}else if (i == 2){    llOwnerSay(llList2CSV(listnumber2));}else if (i == 3){    /// and so forth...}

 

Link to comment
Share on other sites

The LSL is badly lacking a concept of pointer, instead when a function argument is a list it puts the whole object on the stack instead of a reference to it. With that in mind if the lists are short, you can write as user function looking like below and then call it every time you need to choose a list.

However I would not recommend it for long lists because you may run out of memory as the function above would use double list length memory. So for long lists in-line code would be preferrable..

 

list SelectList(integer n)
{
list wlst;
if(n==1) wlst = listnumber1;
else if(n==2) wlst = listnumber2;
else if(n==3) wlst = listnumber3;
...
}

default{ state_entry()
{ list listnumber1= [1,2,3]; list listnumber2= [4,5,6]; llOwnerSay(llDumpList2String(SelectList(2), ","));
}}
 

 

Link to comment
Share on other sites

You can not call a list by name. A compiler can not do such things. Pointers are used for that but LSL has no pointers. 
But you can do alot more with lists as it seems on the 1st look.

- You can copy a list on a temporary working list and copy back the changed list (if needed) as described above. Works for small lists and is a bit clumsy.

- You can use a strided list. Just a simple calculation is needed to get the position of the n'th element of list #x.

- If the list elements belonging to one "record" are of variable length you put everything up in one list using "key","value1",value2" for example.

- For a 2 dimensional array I store 1 dimension in a string with elements separated by "|" for example and the other dimension are the list elements. Access by llList2String(llParseString2List(llList2String(L,x),["|"],[]),y); (with list=L and x,y the position in the 2D-array.

There is more. Is all depends on the specific case. You can do everything with lists even if not everything may be useful. :D

 

Link to comment
Share on other sites

Oh, how I wish LSL and other interpreters allowed this.

During my college days, the elderly engineering school timeshare system had a BASIC interpreter that did just what you want. Placing an escape character (I think it might have been an exclamation point) in front of a string variable caused it to be evaluated in place, then interpreted. It was a super cool feature that I used to cheat like crazy in my "Compiler Design" course.

Code like yours would have worked on that system, as would this...

A=16

A$=A

B$="sqrt"

C$="print !B$(!A)!B$(!A$)"

Typing !C$ at the command prompt would produce

44

My example (and yours) don't even scratch the surface of what you could do with this (like design a compiler or interpreter).

Wouldn't it be neat to have it in LSL?

 

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...