Killi Cloud Posted September 2, 2015 Share Posted September 2, 2015 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? Link to comment Share on other sites More sharing options...
Xiija Posted September 2, 2015 Share Posted September 2, 2015 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? Link to comment Share on other sites More sharing options...
revochen Mayne Posted September 2, 2015 Share Posted September 2, 2015 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); }} Link to comment Share on other sites More sharing options...
Freya Mokusei Posted September 2, 2015 Share Posted September 2, 2015 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! Link to comment Share on other sites More sharing options...
Freya Mokusei Posted September 2, 2015 Share Posted September 2, 2015 Ha, nice! Seems we had the same idea. I like the idea of adding integer IDs to the list to denote the strides. Link to comment Share on other sites More sharing options...
revochen Mayne Posted September 2, 2015 Share Posted September 2, 2015 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. Link to comment Share on other sites More sharing options...
Killi Cloud Posted September 2, 2015 Author Share Posted September 2, 2015 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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