Jump to content
Sign in to follow this  
Killian Jayaram

String to list name ?

Recommended Posts

I am tring to make a short script that uses lists to customise the object (IE Themes saved in lists) but tring to slim down the script and make it so you can select themes from dialog but what i am looking to do it create the list name from string.

list theme_1 = ["<1.00,1.00,1.00>","<1.00,1.00,1.00>","<1.00,1.00,1.00>"];
list theme_2 = ["<1.00,0.00,1.00>","<0.00,0.00,0.00>","<1.00,1.00,0.00>"];
list theme_3 = ["<1.00,1.00,0.00>","<1.00,1.00,1.00>","<1.00,0.00,1.00>"];

ChangeTheme(list theme_select){
    // WOULD MAKE THE COLORS HERE FROM LIST
}

default
{
     touch_end(integer total_number)
    {
        string theme_name = "theme_"+(string)llGetTime();
        ChangeTheme((list)theme_name);
    }
}

Now this does run but does not run (lets say i held down for click (touch) for one second it does not run "theme_1" it tries to run theme_name.

Any idea's how i can get this to make this select the list with out making a if(){} for evey number?

Share this post


Link to post
Share on other sites

you can't use a string as a pointer to a list like that,

 you have to compare strings, and then do  IF statements? ( sorry, only way)

 

 kinda like so

list theme_1 = ["one","<1.00,1.00,1.00>","<1.00,1.00,1.00>","<1.00,1.00,1.00>"];list theme_2 = ["two","<1.00,0.00,1.00>","<0.00,0.00,0.00>","<1.00,1.00,0.00>"];list theme_3 = ["three","<1.00,1.00,0.00>","<1.00,1.00,1.00>","<1.00,0.00,1.00>"];ChangeTheme(){ // WOULD MAKE THE COLORS HERE FROM LIST  if(theme_name == "theme_1")  { currList = theme_1;  }   llOwnerSay("changing " + llList2String(currList,0) );}integer count;integer position;string theme_name;list currList;default{     touch_end(integer total_number)    {   ++count;        position = count%3 + 1;        theme_name = "theme_"+(string)position;        ChangeTheme();    }}

  put this in a cube and keep clicking it .. the user function will fire when its on the *theme_1* list?

Share this post


Link to post
Share on other sites

I'm often using strided lists and search for elements by using llListFindList

 

list themes = [1, "<1.00,1.00,1.00>","<1.00,1.00,1.00>","<1.00,1.00,1.00>",                    2, "<1.00,0.00,1.00>","<0.00,0.00,0.00>","<1.00,1.00,0.00>",                    3, "<1.00,1.00,0.00>","<1.00,1.00,1.00>","<1.00,0.00,1.00>"];integer touch_count = 0;ChangeTheme(integer theme_index){    // WOULD MAKE THE COLORS HERE FROM LIST    list theme_color = llList2List(themes, theme_index+1, theme_index+3);}default{     touch_end(integer total_number)    {        touch_count++;        ChangeTheme(touch_count%3);    }}

 

Thats a very easy way to have some kind of associated lists like for a color menu:

 

list color_names = ["red", "green", "blue"];list color_values = [<1,0,0>, <0,1,0>, <0,0,1>];GetValueByName(string cname){      integer index = llListFindList(color_names, [cname]);      if(index > -1)      {       // get the associated color             vector color = llList2Vector(color_values, index);       }}default{     touch_end(integer num)     {          // get a color name, usually by menu input          string color_name = llList2String(color_names, (integer)llFrand(llGetListLength(color_names)-1);          GetValueByName( color_name);     }}

 

Share this post


Link to post
Share on other sites


Killian Jayaram wrote:

 

Any idea's how i can get this to make this select the list with out making a if(){} for evey number?

While you can't use strings to build variable names, or use arrays in SL, you can use strided lists.

From the look of your lists, each 'theme_' is a fixed number of items long? If that stays consistent then you can use strided lists, too!

Rather than using ifs or text comparisons you'd be able to iterate through strides using an integer-based index, like an informal array.

list lThemes = ["<1.00,1.00,1.00>","<1.00,1.00,1.00>","<1.00,1.00,1.00>,                      "<1.00,0.00,1.00>","<0.00,0.00,0.00>","<1.00,1.00,0.00>",                      "<1.00,1.00,0.00>","<1.00,1.00,1.00>","<1.00,0.00,1.00>"];list lgetStride(integer index){    list lreturnList = [];    integer istrideLength = 3;    integer i;    for(i = 0; i < istrideLength; i++)    {        lreturnList += [llList2String(lThemes,index * istrideLength + i)];    }   return lreturnList;}

Hope this helps!

Share this post


Link to post
Share on other sites

I use it very often, especially on menus like for a color menu. It helps to avoid a whole bunch of IF/ELSE IF statements and works on any situation, where the option has to execute the same specific function but different parameters. :)

Share this post


Link to post
Share on other sites


Freya Mokusei wrote:

Killian Jayaram wrote:

 

Any idea's how i can get this to make this select the list with out making a if(){} for evey number?

While you can't use strings to build variable names, or use arrays in SL, you
can
use strided lists.

From the look of your lists, each 'theme_' is a fixed number of items long? If that stays consistent then you can use strided lists, too!

Rather than using ifs or text comparisons you'd be able to iterate through strides using an integer-based index, like an informal array.
list lThemes = ["<1.00,1.00,1.00>","<1.00,1.00,1.00>","<1.00,1.00,1.00>,                      "<1.00,0.00,1.00>","<0.00,0.00,0.00>","<1.00,1.00,0.00>",                      "<1.00,1.00,0.00>","<1.00,1.00,1.00>","<1.00,0.00,1.00>"];list lgetStride(integer index){    list lreturnList = [];    integer istrideLength = 3;    integer i;    for(i = 0; i < istrideLength; i++)    {        lreturnList += [llList2String(lThemes,index * istrideLength + i)];    }   return lreturnList;}

Hope this helps!


revochen Mayne wrote:

I'm often using strided lists and search for elements by using llListFindList

 
list themes = [1, "<1.00,1.00,1.00>","<1.00,1.00,1.00>","<1.00,1.00,1.00>",                    2, "<1.00,0.00,1.00>","<0.00,0.00,0.00>","<1.00,1.00,0.00>",                    3, "<1.00,1.00,0.00>","<1.00,1.00,1.00>","<1.00,0.00,1.00>"];integer touch_count = 0;ChangeTheme(integer theme_index){    // WOULD MAKE THE COLORS HERE FROM LIST    list theme_color = llList2List(themes, theme_index+1, theme_index+3);}default{     touch_end(integer total_number)    {        touch_count++;        ChangeTheme(touch_count%3);    }}

 

Thats a very easy way to have some kind of associated lists like for a color menu:

 
list color_names = ["red", "green", "blue"];list color_values = [<1,0,0>, <0,1,0>, <0,0,1>];GetValueByName(string cname){      integer index = llListFindList(color_names, [cname]);      if(index > -1)      {       // get the associated color             vector color = llList2Vector(color_values, index);       }}default{     touch_end(integer num)     {          // get a color name, usually by menu input          string color_name = llList2String(color_names, (integer)llFrand(llGetListLength(color_names)-1);          GetValueByName( color_name);     }}

 

 

Thanks there is always a workaround! xD

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.

Sign in to follow this  

×
×
  • Create New...