Jump to content

Simple color change script for attachment


Suki Hirano
 Share

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

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

Recommended Posts

I found this opensource script on another website that provides a simple menu for picking several pre-assigned colors and made a few changes:

// when touched, present a dialog with four color choices
 
integer CHANNEL = 42; // dialog channel
list MENU_MAIN = ["pink", "tiger", "orange", "green", "purple", "blue", "darkblue", "teal", "...more colors"]; // the main menu
list MENU_OPTIONS = []; // a submenu
 
default {
state_entry()
 
{
llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
}
touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "What color to dye?", MENU_MAIN, CHANNEL); // present dialog on click
}
listen(integer channel, string name, key id, string message)
{
if (llListFindList(MENU_MAIN + MENU_OPTIONS, [message]) != -1)  // verify dialog choice
{
llSay(0, name + " picked the option '" + message + "'."); // output the answer
if (message == "...more colors")
llDialog(id, "Pick a color!", MENU_OPTIONS, CHANNEL); // present submenu on request
else if (message == "...Back")
llDialog(id, "What do you want to do?", MENU_MAIN, CHANNEL); // present main menu on request to go back
// here you have the name and key of the user and can easily verify if they have the permission to use that option or not
else if (message == "pink")
llSetColor(<227,158,155>, ALL_SIDES);
else if (message == "tiger")
llSetColor(<108,82,57>, ALL_SIDES);
else if (message == "orange")
llSetColor(<195,170,116>, ALL_SIDES);
else if (message == "green")
llSetColor(<0,125,0>, ALL_SIDES);
else if (message == "purple")
llSetColor(<127,0,127>, ALL_SIDES);
else if (message == "blue")
llSetColor(<0,0,255>, ALL_SIDES);
else if (message == "darkblue")
llSetColor(<0,0,127>, ALL_SIDES);
else if (message == "teal")
llSetColor(<0,127,127>, ALL_SIDES);
} else
llSay(0, name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice
}
}

 But it doesn't seem to work. It does say "Suki picked the option red!" in chat, but it doesn't actually change the color. Also if I pick "pink" "tiger" or "orange" it would say "picked invalid option" (the last line of code), not sure why these are not registering as color choices?

Link to comment
Share on other sites

One problem is that it's not using LSL colour values, which are all floats between 0.0 and 1.0.   Fortunately, that's easily fixed -- just divide these decimal values by 255.   

Not quite sure why it's telling you things are invalid choices, but it may well be the lack of bracketing that's confusing matters.

Try this

integer CHANNEL = 42; // dialog channellist MENU_MAIN = ["pink",<227,158,155>, "tiger",<108,82,57>, "orange",<195,170,116>, "green",<0,125,0> ,"purple",<127,0,127>, "blue",<0,0,255>, "darkblue",<0,0,127>, "teal",<0,127,127>, "...more colors"]; // the main menulist MENU_OPTIONS = []; // a submenulist buttons;default {    state_entry()    {        llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)        buttons = llList2ListStrided(MENU_MAIN,0,-1,2); // pull out the first item in each pair of values    }    touch_start(integer total_number)    {        llDialog(llDetectedKey(0), "What color to dye?", buttons, CHANNEL); // present dialog on click    }    listen(integer channel, string name, key id, string message)    {        if (llListFindList(buttons + MENU_OPTIONS, [message]) != -1)  // verify dialog choice        {            llSay(0, name + " picked the option '" + message + "'."); // output the answer            if (message == "...more colors"){                llDialog(id, "Pick a color!", MENU_OPTIONS, CHANNEL); // present submenu on request            }            else if (message == "...Back"){                llDialog(id, "What do you want to do?", MENU_MAIN, CHANNEL); // present main menu on request to go back                // here you have the name and key of the user and can easily verify if they have the permission to use that option or not            }            else{                integer n = llListFindList(MENU_MAIN,[message]);                if(~n){                    vector v = llList2Vector(MENU_MAIN,(n+1))/255.0;                    llSetColor(v,ALL_SIDES);                }                llDialog(id, "What color to dye?", buttons, CHANNEL); // present dialog on click            }        }        else{            llSay(0, name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice        }    }}

 

Link to comment
Share on other sites

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