Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Color Changing Script

Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
11-14-2005 11:52
This is a touched up version of a script I posted a long time ago.

Usage:
color #RRGGB
Set color by hex code.
Example: /1color #00ccff

color <R,G,B>
Set color by vector. Can be 0.0 - 1.0 or 0 - 255. Only the opening bracket really matters. Note that <1,1,1> will be treated as white (#ffffff), not almost black (#010101).
Example: /1color < 255 128 192

color name
Set color by name. Spaces and capitalization don't matter.
Example: /1color Carnation Pink

listcolors
List known color names. (slow)

CODE
// This code is public domain.
// masa was here 20050302, 20051102, 20051114

integer CHANNEL = 1; // channel to listen for commands on
integer OWNER_ONLY = TRUE; // only owner can control
integer USE_OWNER_SAY = TRUE; // use llOwnerSay() to talk to owner
integer USE_IMS = TRUE; // send IMs instead of using chat
string COMMAND_CHANGE_COLOR = "color"; // command to change color
string COMMAND_LIST_COLORS = "listcolors"; // command to list colors
integer MAX_CHAT_LENGTH = 255; // max size for one message
string PREFIX_HEX = "#"; // prefix to specify hex code
string PREFIX_VECTOR = "<"; // prefix to specify vector code
list LINKS_TO_SET = [LINK_SET, ALL_SIDES]; // [link number, link face, ...]

list COLORS;

integer listen_id;

// Initialize COLORS list
// LSL can't seem to handle large list definitions, so it has to be
// broken up. Note that you may get syntax errors and need to rearrange
// this list if you change the script much.
init_colors() {
COLORS = [
// http://halflife.ukrpack.net/csfiles/help/colors.shtml
"steelblue", "#4682B4", "royalblue", "#041690", "cornflowerblue", "#6495ED",
"lightsteelblue", "#B0C4DE", "mediumslateblue", "#7B68EE", "slateblue", "#6A5ACD",
"darkslateblue", "#483D8B", "midnightblue", "#191970", "navy", "#000080",
"darkblue", "#00008B", "mediumblue", "#0000CD", "blue", "#0000FF",
"dodgerblue", "#1E90FF", "deepskyblue", "#00BFFF", "lightskyblue", "#87CEFA",
"skyblue", "#87CEEB", "lightblue", "#ADD8E6", "powderblue", "#B0E0E6",
"azure", "#F0FFFF", "lightcyan", "#E0FFFF", "paleturquoise", "#AFEEEE",
"mediumturquoise", "#48D1CC", "lightseagreen", "#20B2AA", "darkcyan", "#008B8B",
"teal", "#008080", "cadetblue", "#5F9EA0", "darkturquoise", "#00CED1"
] + [
"aqua", "#00FFFF", "cyan", "#00FFFF", "turquoise", "#40E0D0",
"aquamarine", "#7FFFD4", "mediumaquamarine", "#66CDAA", "darkseagreen", "#8FBC8F",
"mediumseagreen", "#3CB371", "seagreen", "#2E8B57", "darkgreen", "#006400",
"green", "#008000", "forestgreen", "#228B22", "limegreen", "#32CD32",
"lime", "#00FF00", "chartreuse", "#7FFF00", "lawngreen", "#7CFC00",
"greenyellow", "#ADFF2F", "yellowgreen", "#9ACD32", "palegreen", "#98FB98",
"lightgreen", "#90EE90", "springgreen", "#00FF7F", "mediumspringgreen", "#00FA9A",
"darkolivegreen", "#556B2F", "olivedrab", "#6B8E23", "olive", "#808000",
"darkkhaki", "#BDB76B", "darkgoldenrod", "#B8860B", "goldenrod", "#DAA520",
"gold", "#FFD700", "yellow", "#FFFF00", "khaki", "#F0E68C", "palegoldenrod", "#EEE8AA"
] + [
"blanchedalmond", "#FFEBCD", "moccasin", "#FFE4B5", "wheat", "#F5DEB3",
"navajowhite", "#FFDEAD", "burlywood", "#DEB887", "tan", "#D2B48C",
"rosybrown", "#BC8F8F", "sienna", "#A0522D", "saddlebrown", "#8B4513",
"chocolate", "#D2691E", "peru", "#CD853F", "sandybrown", "#F4A460",
"darkred", "#8B0000", "maroon", "#800000", "brown", "#A52A2A",
"firebrick", "#B22222", "indianred", "#CD5C5C", "lightcoral", "#F08080",
"salmon", "#FA8072", "darksalmon", "#E9967A", "lightsalmon", "#FFA07A",
"coral", "#FF7F50", "tomato", "#FF6347", "darkorange", "#FF8C00",
"orange", "#FFA500", "orangered", "#FF4500", "crimson", "#DC143C",
"red", "#FF0000", "deeppink", "#FF1493", "fuchsia", "#FF00FF"
] + [
"magenta", "#FF00FF", "hotpink", "#FF69B4", "lightpink", "#FFB6C1",
"pink", "#FFC0CB", "palevioletred", "#DB7093", "mediumvioletred", "#C71585",
"purple", "#800080", "darkmagenta", "#8B008B", "mediumpurple", "#9370DB",
"blueviolet", "#8A2BE2", "indigo", "#4B0082", "darkviolet", "#9400D3",
"darkorchid", "#9932CC", "mediumorchid", "#BA55D3", "orchid", "#DA70D6",
"violet", "#EE82EE", "plum", "#DDA0DD", "thistle", "#D8BFD8",
"lavender", "#E6E6FA", "ghostwhite", "#F8F8FF", "aliceblue", "#F0F8FF",
"mintcream", "#F5FFFA", "honeydew", "#F0FFF0", "lightgoldenrodyellow", "#FAFAD2",
"lemonchiffon", "#FFFACD", "cornsilk", "#FFF8DC", "lightyellow", "#FFFFE0",
"ivory", "#FFFFF0", "floralwhite", "#FFFAF0", "linen", "#FAF0E6"
] + [
"oldlace", "#FDF5E6", "antiquewhite", "#FAEBD7", "bisque", "#FFE4C4 ",
"peachpuff", "#FFDAB9", "papayawhip", "#FFEFD5", "beige", "#F5F5DC",
"seashell", "#FFF5EE", "lavenderblush", "#FFF0F5", "mistyrose", "#FFE4E1",
"snow", "#FFFAFA", "white", "#FFFFFF", "whitesmoke", "#F5F5F5",
"gainsboro", "#DCDCDC", "lightgrey", "#D3D3D3", "silver", "#C0C0C0",
"darkgray", "#A9A9A9", "gray", "#808080", "lightslategray", "#778899",
"slategray", "#708090", "dimgray", "#696969", "darkslategray", "#2F4F4F",
"black", "#000000"
] + [
// :o
"carnationpink", "#FA7FC1"
];
}

// Create/recreate listener
init_listen() {
llListenRemove(listen_id);
if ( OWNER_ONLY )
listen_id = llListen( CHANNEL, "", llGetOwner(), "" );
else
listen_id = llListen( CHANNEL, "", NULL_KEY, "" );
}

// Send a message to the specified id, based on settings
say(key id, string str) {
if ( id == llGetOwner() && USE_OWNER_SAY ) llOwnerSay( str );
else if ( USE_IMS ) llInstantMessage( id, str );
else llWhisper(0, str);
}

// Convert a #RRGGBB style color string to an LSL vector color
vector color_from_hex(string str) {
return <(integer)("0x" + llGetSubString(str,1,2)),
(integer)("0x" + llGetSubString(str,3,4)),
(integer)("0x" + llGetSubString(str,5,6))> / 255;
}

// Convert a vector color string to an LSL vector color
// Supports ranges 0.0-1.0 and 0-255
// caveat: 1,1,1 will be treated as #ffffff, not #010101
vector color_from_vector(string vec) {
list l = llParseString2List(vec, [" ", ",", "<", ">"], []);
vector v;

v.x = (float)llList2String(l, 0);
v.y = (float)llList2String(l, 1);
v.z = (float)llList2String(l, 2);

if ( v.x > 1 || v.y > 1 || v.z > 1 ) v /= 255;

return v;
}

// Remove all spaces from a string
string strip_spaces(string str) {
return llDumpList2String( llParseString2List(str, [" "], []), "" );
}

// Convert a color name to an LSL vector color
vector color_from_name(string name) {
integer x = llListFindList( COLORS, [llToLower(strip_spaces(name))] );
if ( x == -1 ) return <-1,-1,-1>;
return color_from_hex( llList2String(COLORS, x+1) );
}

// Set configured links/faces to the color specified by str
set_color(key id, string str) {
vector color;
integer i;
if ( llGetSubString(str, 0, 0) == PREFIX_HEX ) // hex code
color = color_from_hex( str );
else if ( llGetSubString(str, 0, 0) == PREFIX_VECTOR ) // vector
color = color_from_vector( str );
else
color = color_from_name( str );

if ( color.x < 0 || color.x > 1 || color.y < 0 || color.y > 1 || color.z < 0 || color.z > 1 ) {
say( id, "Invalid color specified: " + str );
return;
}

for ( i = 0; i < llGetListLength( LINKS_TO_SET ); i += 2 )
llSetLinkColor( llList2Integer(LINKS_TO_SET, i), color, llList2Integer(LINKS_TO_SET, i+1) );
}

// List known color names
list_colors(key id) {
string str = "";
string nstr = "";
integer i;

for ( i = 0; i < llGetListLength( COLORS ); i += 2 ) {
nstr = str + llList2String(COLORS, i) + ", ";

if ( llStringLength(nstr) > MAX_CHAT_LENGTH ) {
say(id, str);
str = llList2String(COLORS, i) + ", ";
} else {
str = nstr;
}
}
if ( str != "" ) say(id, str);
}

default {
state_entry() {
init_colors();
init_listen();
}

on_rez(integer param) {
init_listen();
}

changed(integer what) {
if ( what & CHANGED_OWNER )
init_listen();
}

listen(integer channel, string name, key id, string msg) {
string command;
string argument;
list l;

l = llParseStringKeepNulls( msg, [" "], [] );
command = llList2String(l, 0);
argument = llDumpList2String( llList2List(l, 1, -1), " " );

if ( command == COMMAND_CHANGE_COLOR )
set_color(id, argument);
else if ( command == COMMAND_LIST_COLORS )
list_colors(id);

}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
11-15-2005 07:26
/15/19/71657/1.html
_____________________
i've got nothing. ;)
HulkHogan Hogarth
Registered User
Join date: 15 Mar 2007
Posts: 31
06-16-2007 06:25
idk if im putting this into the script right but i keep getting syntex errors?
Dez Singh
NooB
Join date: 25 Apr 2007
Posts: 12
:d
05-14-2008 13:02
I love you, thank you so much..
Been looking for a script like this for ages!
When you feel like a challenge, try making this script with a menue. ^^
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
05-15-2008 08:20
What's the point of the on_rez event? You initialize the listen in the state entry.
Renee Roundfield
Registered User
Join date: 10 Mar 2006
Posts: 278
05-15-2008 09:29
Dez, IM me in world. I have menu driven script like this.
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
05-15-2008 09:33
huge unpacked code with huge unpacked database of color definition looks inefficient but at least fast to execute.

you need procedures, expecially procedures that convert hex 2 integer in 2 steps, and back.
you also need to learn what "<<" and ">>" do.
Declaring "<" as global string that is more than 12 letters in the source makes me cry.
KickMe Sideways
Registered User
Join date: 30 May 2008
Posts: 17
Syntax errors
06-06-2008 10:44
From: HulkHogan Hogarth
idk if im putting this into the script right but i keep getting syntex errors?



Put another closing bracket at the end. Worked for me

this one }
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-08-2008 21:05
i'm trying to modify this script to initialize the listen when it receives a specific link message. but it still does it when a different link message is received. i removed the init_listen funtions and added this function:

From: someone


link_message(integer sender_num,integer num, string listenon, key id){
if (listenon == "colormenu";)
listento = id;
llWhisper(CHANNEL, "Entering Color Change mode. I will listen to " + llKey2Name(id) + " for " + (string) TIME + " seconds.";);
llInstantMessage(listento, "say 'candle+color name' to change the colors of the candles. IE: candle red.";);
llSetTimerEvent((float) TIME);
llListen(CHANNEL,"", listento, "";);



and a timer to remove the listen after 30 seconds

i'm using a menu script in a different prim that sends strings in the link messages depending on the choice. but even if i choose something other than the color change, the color change gets initialized, but the thing is the color change choice sends the key of the avatar to listen to as id. all of the other choice commands send null key, so of course i get errors about invalid keys. i tried using a return function:

From: someone
else
{return;}

but i don't understand how to use it, and i can't figure out how to make it compile in the script
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
09-08-2008 21:39
The problem is in your link_message function.

If an if statement evaluates false, it will only affect the very next function. In this case, it is your "listento=id;" function. Then, regardless of the evaluation of the if statement, it will go on to do the rest of the functions.

What you need to do is separate out all of those things you want done *only* on a TRUE evaluation of the if statement. Use curly braces around the whole set, as so . . .



From: someone

link_message(integer sender_num,integer num, string listenon, key id){
if (listenon == "colormenu";)
{
listento = id;
llWhisper(CHANNEL, "Entering Color Change mode. I will listen to " + llKey2Name(id) + " for " + (string) TIME + " seconds.";);
llInstantMessage(listento, "say 'candle+color name' to change the colors of the candles. IE: candle red.";);
llSetTimerEvent((float) TIME);
llListen(CHANNEL,"", listento, "";);
}

Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-08-2008 21:56
aaah ok, thanks so much
Lizardbeth Lulu
Stays crunchy in milk
Join date: 4 Jul 2005
Posts: 15
09-12-2008 20:28
I have an item that has different groups of prims that I would like to control the color of seperately. This color change script worked fine for each independant prinm when unlinked. When I linked the prims together, the script changed EVERY prim in the object to the input color, including prims without this script. All I changed in the script was this line:

string COMMAND_CHANGE_COLOR = "word";

whereas each group of prims would have their own key word.

Is there something different I need to do to get the script working correctly? I know it's possible to change colors of prims independantly in one single linked object, as I've owned objects that have done this. I know nothing about scripting though so I'm at a total loss. :(
_____________________
www.lizardbeth.net
-My Art Stuffs-
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-13-2008 00:20
what do you have in the list of LINK_TO_SET?

the list can say what it is, or

list LINKS_TO_SET = [1,3,2, ALL_SIDES,5,2,4,3]; // [link 1, face 3,link2, all faces ...]
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Lizardbeth Lulu
Stays crunchy in milk
Join date: 4 Jul 2005
Posts: 15
09-13-2008 13:58
the link-to is set to All. I didn't change that from what the OP posted because I didn't know what that field did.

How would I properly fill in that field? Lets say there's 3 sections in my object that I want to change the colors for. Do I list all 3 group types in that definition? or do I only list one and the script will know "all prims with this identical script in it defining the same link-to will change color, but nothing else"?

I have no idea how SL cripting works as up until now I've done very basic "put this free script in the box and magic happens and it works", so feel free to explain it in kindergarden terms. ;^_^ My feelings won't be hurt.
_____________________
www.lizardbeth.net
-My Art Stuffs-
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-13-2008 16:08
From: Lizardbeth Lulu
the link-to is set to All. I didn't change that from what the OP posted because I didn't know what that field did.

How would I properly fill in that field? Lets say there's 3 sections in my object that I want to change the colors for. Do I list all 3 group types in that definition? or do I only list one and the script will know "all prims with this identical script in it defining the same link-to will change color, but nothing else"?

I have no idea how SL cripting works as up until now I've done very basic "put this free script in the box and magic happens and it works", so feel free to explain it in kindergarden terms. ;^_^ My feelings won't be hurt.



well if you're using seperate command words for each group, you would need to assign the group in that list for that script. you would need a seperate script for each section. there are more advanced scripts that can handle multiple lists, but they can be even more complex than this one
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369