Colour change script

From The SchomEmunity Wiki
Jump to: navigation, search

(From Wheelo's bubble suit)
Due to popular demand, I am posting the colour change script from my suit here.
It is not case-sensitive, and now works if you type other words along with the colour.
Oh, and I don't know what mauve looks like...so I left it out.

//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( 0, "", NULL_KEY, "" );
    }

    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);
    }
}

To use, simply type a colour!
Examples:

  • "blue"
  • "BLUE"
  • "i'm feeling a bit blue today"
  • "kljashfljasfBLUEklasjbf"

Possible applications include lights, walls, outfits, anything that needs to change colour really.