Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

color change script problems

Durandal Bosatsu
Registered User
Join date: 12 Oct 2007
Posts: 3
06-15-2008 18:24
i have tried many things to fix this script, it works for me but when i give someone the scripted item it doesnt work, and when i give a color change command it works on other people with the armor so if i wanna be blue and someone with the same armor is by me it changes there's too

here's the script:
//declare the 'checkForColour' function
checkForColour(string colour,string message){
//change the typed sentence to lowercase, to avoid case-sensitivity
string lowerSentence = llToLower(message);
string newColour = llToLower(colour);
//check if a colour was found in the sentence
integer saidColour = llSubStringIndex(lowerSentence,newColour);
//if it is not found, the SubStringIndex function returns -1
//so if it is not -1, the colour must have been said
if(saidColour != -1){
//call the changeColour function, pass the variable newColour (the colour to change it to)
changeColour(newColour);
}
}

//declare a function called 'changeColour'
changeColour(string changeTo){
//change the colour of all sides of the prim according to what colour was said
if(changeTo == "red";){
llSetColor(<1,0,0>,ALL_SIDES);
}else if(changeTo == "orange";){
llSetColor(<1,0.50196,0>,ALL_SIDES);
}else if(changeTo == "yellow";){
llSetColor(<1,1,0>,ALL_SIDES);
}else if(changeTo == "green";){
llSetColor(<0,1,0>,ALL_SIDES);
}else if(changeTo == "blue";){
llSetColor(<0,0,1>,ALL_SIDES);
}else if(changeTo == "purple";){
llSetColor(<0.50196,0,1>,ALL_SIDES);
}else if(changeTo == "white";){
llSetColor(<1,1,1>,ALL_SIDES);
}else if(changeTo == "black";){
llSetColor(<0,0,0>,ALL_SIDES);
//}else if(changeTo == "mauve";){
//llSetColor(<>,ALL_SIDES);
}else if(changeTo == "brown";){
llSetColor(<0.36078,0.18039,0>,ALL_SIDES);
}else if(changeTo == "pink";){
llSetColor(<1,0,1>,ALL_SIDES);
}else if(changeTo == "lilac";){
llSetColor(<0,1,1>,ALL_SIDES);
}else if(changeTo == "turquoise";){
llSetColor(<0,1,0.50196>,ALL_SIDES);
}else if(changeTo == "maroon";){
llSetColor(<0.50196,0,0>,ALL_SIDES);
}else if(changeTo == "grey";){
llSetColor(<0.50196,0.50196,0.50196>,ALL_SIDES);
}
}

default
{
//set up a listener with no filters
state_entry()
{
llListen(5,"",llGetOwner(),"";);
}

listen( integer channel, string name, key id, string message )
{
//call the 'checkForColour' function, pass the variables of colour to check for and sentence recieved
checkForColour("red",message);
checkForColour("orange",message);
checkForColour("yellow",message);
checkForColour("green",message);
checkForColour("blue",message);
checkForColour("purple",message);
checkForColour("white",message);
checkForColour("black",message);
checkForColour("mauve",message);
checkForColour("white",message);
checkForColour("brown",message);
checkForColour("pink",message);
checkForColour("lilac",message);
checkForColour("turquoise",message);
checkForColour("maroon",message);
checkForColour("grey",message);
}
}
Cory Fimicoloud
Registered User
Join date: 23 May 2007
Posts: 5
06-15-2008 19:01
CODE
integer iListenHandle = 0;
//declare the 'checkForColour' function
checkForColour(string colour,string message){
//change the typed sentence to lowercase, to avoid case-sensitivity
string lowerSentence = llToLower(message);
string newColour = llToLower(colour);
//check if a colour was found in the sentence
integer saidColour = llSubStringIndex(lowerSentence,newColour);
//if it is not found, the SubStringIndex function returns -1
//so if it is not -1, the colour must have been said
if(saidColour != -1){
//call the changeColour function, pass the variable newColour (the colour to change it to)
changeColour(newColour);
}
}

//declare a function called 'changeColour'
changeColour(string changeTo){
//change the colour of all sides of the prim according to what colour was said
if(changeTo == "red"){
llSetColor(<1,0,0>,ALL_SIDES);
}else if(changeTo == "orange"){
llSetColor(<1,0.50196,0>,ALL_SIDES);
}else if(changeTo == "yellow"){
llSetColor(<1,1,0>,ALL_SIDES);
}else if(changeTo == "green"){
llSetColor(<0,1,0>,ALL_SIDES);
}else if(changeTo == "blue"){
llSetColor(<0,0,1>,ALL_SIDES);
}else if(changeTo == "purple"){
llSetColor(<0.50196,0,1>,ALL_SIDES);
}else if(changeTo == "white"){
llSetColor(<1,1,1>,ALL_SIDES);
}else if(changeTo == "black"){
llSetColor(<0,0,0>,ALL_SIDES);
}else if(changeTo == "mauve"){
llSetColor(<0.87843, 0.69019, 1.0>,ALL_SIDES);
}else if(changeTo == "brown"){
llSetColor(<0.36078,0.18039,0>,ALL_SIDES);
}else if(changeTo == "pink"){
llSetColor(<1,0,1>,ALL_SIDES);
}else if(changeTo == "lilac"){
llSetColor(<0,1,1>,ALL_SIDES);
}else if(changeTo == "turquoise"){
llSetColor(<0,1,0.50196>,ALL_SIDES);
}else if(changeTo == "maroon"){
llSetColor(<0.50196,0,0>,ALL_SIDES);
}else if(changeTo == "grey"){
llSetColor(<0.50196,0.50196,0.50196>,ALL_SIDES);
}
}

default
{
//set up a listener with no filters
state_entry()
{
llListenRemove(iListenHandle);
iListenHandle = llListen(5,"",llGetOwner(),"");
}

changed(integer change)
{
if (change & CHANGED_OWNER)
{
llListenRemove(iListenHandle);
iListenHandle = llListen(5,"",llGetOwner(),"");
}
}

listen( integer channel, string name, key id, string message )
{
//call the 'checkForColour' function, pass the variables of colour to check for and sentence recieved
checkForColour("red",message);
checkForColour("orange",message);
checkForColour("yellow",message);
checkForColour("green",message);
checkForColour("blue",message);
checkForColour("purple",message);
checkForColour("white",message);
checkForColour("black",message);
checkForColour("mauve",message);
checkForColour("white",message);
checkForColour("brown",message);
checkForColour("pink",message);
checkForColour("lilac",message);
checkForColour("turquoise",message);
checkForColour("maroon",message);
checkForColour("grey",message);
}
}
Durandal Bosatsu
Registered User
Join date: 12 Oct 2007
Posts: 3
06-15-2008 21:19
thank you :D!
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
06-16-2008 01:50
You may want to consider using a simple

on_rez(integer param) { llResetScript(); }

Unless you have some reason not to want to reset the script. In that case, Cory's changed() event is the way to go.

But that's a detail. What motivates my post is how utterly verbose your code is. Here is another approach:

CODE

list ColorNames = ["red", "orange", ... ]; // To complete // All *lower* case!
list ColorValues = [<1.0, 0.0, 0.0>, <1.0, 0.5, 0.0>, ... ]; // To complete
integer ColorNumber;

default
{
on_rez(integer param) { llResetScript(); }

state_entry()
{
ColorNumber = llGetListLength(ColorNames);
llListen(5, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string msg)
{
msg = llToLower(msg);
integer i = 0;
for (; i < ColorNumber; ++i)
{
if (llSubStringIndex(msg, llList2String(ColorNames, i)) != -1)
{
llSetColor(llList2Vector(ColorValues, i), ALL_SIDES);
return;
}
}
}
}


I didn't compile it but I'm confident... ;)