Pat Starship Posted October 29, 2011 Share Posted October 29, 2011 So I have a hud that works off llTouchFaceST and it returns the integer values of each vector1234 as you touch the face.I have then filtering threw a function I made TouchMeLongTime(string K1){if(K1=="3"){MENU("MAIN");}} at times i have many values in a rowif(K1=="3"){MENU("MAIN");}if(K1=="4"){MENU("MAIN");}if(K1=="5"){MENU("MAIN");}if(K1=="6"){MENU("MAIN");}if(K1=="7"){MENU("MAIN");}if(K1=="8"){MENU("MAIN");} how can I make it do a bunch in a row?example no matter what I push (1 threw 8) it knows to preform my event if its press on any of those vectors(1 threw 8).if(K1=="1,2,3,4,5,6,7,8"){MENU("MAIN");} I kow above would not work but I was hoping it explain what I am trying to do.I just like to cut down the string amount by being able to group sections of the face to preform 1 event with out having a string for every vector in that section. Link to comment Share on other sites More sharing options...
Pat Starship Posted October 29, 2011 Author Share Posted October 29, 2011 nvm figure it out TouchMeLongTime(string K1) {list GG = ["34","33","27","26"]; integer i = 0; integer end = llGetListLength(GG); for (; i<end; ++i) {if(K1==llList2String(GG,i)){MENU("MAIN");}} duno if its the right way...but its working .... Link to comment Share on other sites More sharing options...
Qie Niangao Posted October 29, 2011 Share Posted October 29, 2011 Might want to check out llListFindList() to avoid having to loop through the list testing each element for a string match. Link to comment Share on other sites More sharing options...
Kaluura Boa Posted October 29, 2011 Share Posted October 29, 2011 You said yourself that you calculate an integer from the value of llDetectedTouchST()... Why do you convert it into a string? If you transmit an integer to your function TouchMeLongTime(), things are much easier. TouchMeLongTime(integer k){ if ((k >= 1) && (k <= 8)) { Menu("MAIN"); } // else...} I would also point out that it is sub-optimal to use a static string as parameter of a function, especially when all you do is to test this string against other strings, as I guess you do. As a rule, I always try to avoid working with --from worst to best-- lists, strings, rotations, vectors, floats to work only with integers as much as possible. In this case of a menu, I would just define some (pseudo) constants at the beginning of the script and forget about their real values. For example: // Values are irrelevant, they must just be unique.integer MAIN = 1;integer OPTIONS = 2;integer THIS = 3;integer THAT = 4;// etc, etc So you can re-write your Menu() function to use integers. Menu(integer type){ if (type == MAIN) { // Main menu } else if (type == OPTIONS) { // Option menu } // etc, etc} Much faster --to type too--, less memory hungry... And with integers, or numeric values in general, it is easy to check if a value is within a range, like for example: if ((type != MAIN) && (type < THAT)){ // Special case} Just think of strings as a plague and avoid them! ;-) 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