Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

color vector input

Ursula Madison
Chewbacca is my co-pilot
Join date: 31 Jul 2004
Posts: 713
06-03-2005 21:50
Hey folks... I'm working on a script to change the colors of a set of wings I've made. I've figured out how to use llSetLinkColor to change both the wings and the skeletal struts seperately, so each prim doesn't have to have a script (the brain is in the parent prim, the wing membranes are link numbers 2-5, and the struts are link numbers 6+, so that part is fairly straightforward).

The thing that's puzzling me is getting the end user's color selection into a vector usable by the script. I know I could just predefine a list of colors that the user could choose from... but I was wondering about letting them choose the actual vector themselves so as not to limit the color choices.

It seems like I'd have to have a llListen in there, and then pull the values out of the resulting string, plugging them into the color vector variable, but I'm not sure how to get there. Any suggestions?
_____________________
"Huh... did everything just taste purple for a second?" -- Philip J. Fry
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
06-03-2005 23:06
Hi Ursula,

If you're willing to ask your customers to use proper vector syntax in their command chats, you can just cast the chat fragment directly into a vector.

(I'm not on right now, so this isn't tested)
CODE

//
// Should respond to /setcolor <0.96,0.72,0.48>
//
listen( integer channel, string name, key id, string msg ) {
string lowercase_msg = llToLower( msg );
if ( 0 == llSubStringIndex( lowercase_msg, "/setcolor " ) ) {
llSetColor( (vector)llDeleteSubString( lowercase_msg, 0, 9 ), ALL_SIDES );
}
}


Trouble is, if they mess up the syntax on the vector, the script is going to gripe at them. It shouldn't crash (I don't think), but it will complain noisily. Which reminds me; I need to cruise over and see if anybody in the Proposals section has asked for exception handlers in LSL :D

If this meets your needs, great! If not, please post back and we'll see if we can come up with a slightly more complicated Plan "B".

-- jj
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
06-03-2005 23:23
I have the perfect solution for this. It's dialog driven, but part of my Game Dev client presently.

Lemme butcher it and test it. I'll post it here once it works on its own.



Edit: There we are. That was simple enough. Simple Dialog-Driven solution with a custom color option. Started with touch, random channel, listener should remove itself when not on:

CODE
// Global variables

integer g_listener = FALSE; // Listen Handler
integer randomChannel = 0; // Our random channel
integer place = 0; // Place in the Script
integer exit = FALSE; // Exit param
vector color = <1,1,1>; // Global color param

list colors = ["Orange","Purple","Lime","Pink","Teal","Gray","Blue","Red","Green","White","Yellow","Custom"];

list custom = ["0.8","0.9","1.0","0.5","0.6","0.7","0.2","0.3","0.4","0.0","0.1"];


default
{
touch_start(integer total_number)
{
if(llDetectedKey(0) == llGetOwner())
{
// Refresh the goods
place = 0;
llListenRemove(g_listener);

// Add a random channel
randomChannel = 10 + (integer)llFrand(100000);
g_listener = llListen(randomChannel,"",llGetOwner(),"");

// Fire up the expiration timer
llSetTimerEvent(720.0);

// Fire up the dialog
llDialog(llGetOwner(),"Select a Color Theme:",colors,randomChannel);
}
}
listen(integer chan, string name, key id, string msg)
{
// When we receive a dialog response...
if(chan == randomChannel) // Redundant, unless you want more chans
{
// This depth is reserved for Configuration Options
if(place == 0)
{
llSetTimerEvent(720.0);
++place;

integer test = llListFindList(colors,(list)msg);
if(test != -1)
{
// If we select "Orange"
if(test == 0)
{
color = <1,0.6,0>;
}

// If we select "Purple"
else if(test == 1)
{
color = <0.6,0,1>;
}

// If we select "Lime"
else if(test == 2)
{
color = <0.6,1,0>;
}

// If we select "Pink"
else if(test == 3)
{
color = <1,0,0.6>;
}

// If we select "Teal"
else if(test == 4)
{
color = <0,1,1>;
}

// If we select "Gray"
else if(test == 5)
{
color = <0.5,0.5,0.5>;
}

// If we select "Blue"
else if(test == 6)
{
color = <0.3,0.3,1>;
}

// If we select "Red"
else if(test == 7)
{
color = <1,0.3,0.3>;
}

// If we select "Green"
else if(test == 8)
{
color = <0.3,1,0.3>;
}

// If we select "White"
else if(test == 9)
{
color = <1,1,1>;
}

// If we select "Yellow"
else if(test == 10)
{
color = <1,1,0>;
}

// If we select "Custom"
else if(test == 11)
{
llDialog(llGetOwner(),"Custom Color Mode Selected! Choose a value for RED (Second Life RGB).",custom,randomChannel);
return;
}

llSetLinkColor(LINK_SET,color,ALL_SIDES);

exit = TRUE;
llSetTimerEvent(0.1);
return;
}
else
llSetTimerEvent(0.1);

}
// This depth is reserved for Custom Colors ONLY!
else if(place == 1)
{
llSetTimerEvent(720.0);
++place;

color.x = (float)msg;
llDialog(llGetOwner(),"Choose a value for GREEN (Second Life RGB).",custom,randomChannel);
}
else if(place == 2)
{
llSetTimerEvent(720.0);
++place;

color.y = (float)msg;
llDialog(llGetOwner(),"Choose a value for BLUE (Second Life RGB).",custom,randomChannel);
}
else if(place == 3)
{
llSetTimerEvent(720.0);
++place;

color.z = (float)msg;

llSetLinkColor(LINK_SET,color,ALL_SIDES);

exit = TRUE;
llSetTimerEvent(0.1);
return;
}
}
}
timer()
{
llSetTimerEvent(0.0);
if(exit == FALSE) llOwnerSay("Timer Expired. Please try again.");
llListenRemove(g_listener);
}
}

I also sent you a copy in-world, since I had this on my person already.
_____________________
---
Ursula Madison
Chewbacca is my co-pilot
Join date: 31 Jul 2004
Posts: 713
06-03-2005 23:51
Holy cow... thanks guys, that's more help than I was expecting. I'll have to log in and see about dovetailing what I've got so far in with this. :D You're my heroes!
_____________________
"Huh... did everything just taste purple for a second?" -- Philip J. Fry