Jump to content
Bo Grafta

List-name as a variable

Recommended Posts

I have four lists.

I want to select one of the four lists depending of a selection.

How can I use a variable instead of the list name. 

 

This example does not work, but I want something like that:          

string ListName="T2";
string texture= llList2String(ListName, counter);

Share this post


Link to post
Share on other sites

the best we can do is to create a wrapper function. Something like:
 

//globals
list t1;
list t2;
list t3;
list t4;

list getListByName(string name)
{
   if (name == "T1")
      return t1;
   if (name == "T2")
      return t2;
   if (name == "T3")
      return t3;
   return t4;
}

...

string ListName = "T2";
string texture = llList2String(getListByName(ListName), counter);

 

  • Like 1

Share this post


Link to post
Share on other sites

Are the four lists the same length?

If so, you could concatenate them and add list number * individual list length to the index when accessing the items:

// four lists of three items each, concatenated
list my_list = 
[
    "A", "B", "C", // list 0
    "D", "E", "F", // list 1
    "G", "H", "I", // list 2
    "J", "K", "L"  // list 3
];

integer individual_list_length = 3;

default
{
    state_entry ()
    {
        integer list_number = 1; // the list numbers run from 0 to 3
        integer list_item = 2; // the items in each list are indexed 0 to 2
        string item = llList2String (my_list, (list_number * individual_list_length) + list_item); // 1 * 3 + 2 = 5
        llOwnerSay (item); // "F"
    }
}

 

  • Like 2

Share this post


Link to post
Share on other sites
Posted (edited)

Yes, they are the same length.

I have considerd to make one list instead of four different en change the index, but first I wanted to know if it was possible to do it at the way I asked.

Thank you verry much Mollymews, it was just what I was looking for!

 

Edited by Bo Grafta
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...