Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llDialog Prim Color Change

ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
03-07-2009 23:03
This script will change the color of the prim when the choice is made in the llDialog menu. People have been asking how to do it, so I figured this would help.

CODE

key owner;
key toucher;
integer menu_channel;
integer listenhandler;
list menu_buttons = ["Blue","Green","Red","Cancel"]; //simple color choices, change for your needs

default
{
state_entry()
{
owner = llGetOwner(); //this identifies the owner when the script is reset or the item is rezzed.
}

touch_start(integer total_number)
{
toucher = llDetectedKey(0); //determine if the person who touched is the owner
if(toucher == owner) //if the toucher is the owner, do this stuff
{
menu_channel = (integer)llGetGMTclock() * -2; //this gives you a random channel based on the gmt clock time, helps keep other objects from interfering with your dialog menu.
listenhandler = llListen(menu_channel,"",toucher,""); //sets up the listen for the dialog choices
llDialog(toucher,"What color would you like?",menu_buttons,menu_channel); //actual dialog menu command
}
else //if toucher is not the owner, tell 'em to go away ;o)
{
llInstantMessage(toucher, "I'm sorry, only the owner may use this.");
}
}
changed(integer change) //reset script if owner changes
{
if(change && CHANGED_OWNER)
{
llResetScript();
}
}
listen(integer menu_channel,string name, key toucher,string choice) //tells the script what to do based on the choice made in the dialog menu
{
llListenRemove(listenhandler); // Stop listening on menu_channel
if(choice == "Blue") //These choices must match exactly the buttons in the list menu_buttons...whatever button is pushed, that will be the message sent from the dialog menu
{
llSetColor(<0,0,1>,ALL_SIDES); //sets object color, ALL_SIDES means all the faces will change to this color. the vector (ie "<0,0,1>" is the <r,g,b> value of the color you want to set.
}
else if(choice == "Green")
{
llSetColor(<0,1,0>,ALL_SIDES);
}
else if(choice == "Red")
{
llSetColor(<1,0,0>,ALL_SIDES);
}
else if(choice == "Cancel")
{
llResetScript();
}
}

}


Tried to comment it as much as I could, so it looks kinda nasty,
but it gives the people asking about it lately a good idea where to start on their own ;)
Sleepy Xue
I script Pretty HUDs
Join date: 22 Jun 2008
Posts: 57
03-08-2009 00:44
Yay for open source. /me is also working on a color changer =]
_____________________
I script pretty HUDs.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
03-08-2009 03:14
In a similar vein...



...notice that the corresponding colour values can also be into a list so that llListFindList can be used in preference to all those if, else if, lines.
_____________________
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
03-08-2009 22:13
lol yeah pale..this isn't the one I use, it's the one I made for a friend to learn some basics from, and be able to reference back to it for little bits of syntax and stuff. I just figured there were enough people asking about them, why not get them started. It works as is, but it's not the most robust ;)
Sleepy Xue
I script Pretty HUDs
Join date: 22 Jun 2008
Posts: 57
03-09-2009 21:04
Yup! I use over a hundred colors. It would be nasty to have hundreds of unneeded loops within my code! Also with a sorted list you may be able to use a Binary Search Tree to cut out time. Not sure if it would be a good or not seeing as it might be strings, but you could turn them into integers and then compare. It's something a friend and I have have been working on for some of our scripts. We shall see if it is really a better thing to do or not (to save time).
_____________________
I script pretty HUDs.