Jump to content

List-name as a variable


Bo Grafta
 Share

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

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

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);

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1492 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
 Share

×
×
  • Create New...