Jump to content

How do I tranform a string into a variable?


Edu Csak
 Share

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

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

Recommended Posts

Hi!

I'm trying to make a script where a item code is given and it grabs its respective menu list, but I can't find on wiki what command I should use to transform the value I've got into a variable of the menu that should be shown.
Example: the item 48 is given. So, the tint48 menu list should be prompted.
I came up with this idea of putting on a list (tintableItems) which contains the item (48), the menu that should prompt (tint48) and then the values that should go on (faces48).
But I'm stucked on how to transform the value I get (tint48) into the list values of it.

I don't even know if it's possible, but I'm searching wiki for this answer but I cannot find.

I'm trying to simplify the coding
Based on the item given, a menu should popup with the values provided.
I don't want to make N lists, one for each item neither nesting neverending IFs to check if item 48

 

integer CHAN= -999;
key old_owner;
integer item=48;
list tintableItems = [
    48,"tint48","faces48"
]; // where 48 is the item / tint48 its menu / faces48 the values 
list tint48 = ["TEETH","ALL","CLOSE","COLLAR","PULL TAB", "BODY"];
list faces48 = ["3","ALL_SIDES","","1","2","0"];


default
{
    state_entry()
    {
        old_owner = llGetOwner();
        if (item == (integer)llList2String(tintableItems, (integer) llListFindList(tintableItems, (list)item))) {
            //integer position = (integer) llListFindList(tintableItems, (list)item)+1; // gets the next position in List
            string value = llList2String(tintableItems, (integer) llListFindList(tintableItems, (list)item)+1); // grabs the value
            // now I want to use this value as parameter which menu list to use but don't know what command to get it done
            llDialog(old_owner, "Choose: ",  (list)value , CHAN);
            llListen(CHAN, "", NULL_KEY, "");
        }
    }

}

 

My problem lies here: llDialog(old_owner, "Choose: ",  (list)value , CHAN); 
I know it's wrong. I just don't know what to do ;)

TY!

Screen Shot 2019-06-25 at 01.56.14.png

Edited by Edu Csak
Link to comment
Share on other sites

we don't have pointers in LSL. So we need a workaround when we want to avoid multiple IF ELSE IF clauses

a way to do this to make and use an indice stored in a list.  Example showing one way how this might be done

// indice into tints and faces. Use negative item value to avoid conflicts
//                  tint  face       tint  face       tint   face
list indice = [-48, 0, 5, 0, 5, -49, 6, 8, 0, 5, -50, 9, 12, 6, 8];

//             0       1     2       3        4           5       6        7     8       9 ...
list tints = ["TEETH","ALL","CLOSE","COLLAR","PULL TAB", "BODY", "FANGS", "ALL, "CLOSE", ...];

list faces = [ .... ];


integer item = 48;

item -= (2 * item);  // negate item for indexing purposes

integer i = llListFindList(indice, [item]);

list menu = llList2List(tints, llList2Integer(tints, i + 1), llList2Integer(tints, i + 2));
 
llDialog(id, "Choose:", menu, chan);  

 

Edited by Mollymews
typr
  • Like 1
Link to comment
Share on other sites

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