Random Color Changer

Written by Kitsune
//  Random Color Changer
//  Created by Water Rogers for IBM/Opensource
 
//  Purpose
//  --------------------------------------------------------------
//  This is a basic example of how you can randomize color
//  It aso shows simple on/off functionality and introduces
//  the llMessageLinked() concept for communicating between
//  multiple objects/scripts of the same link set.
 
//  Requirements
//  --------------------------------------------------------------
//  A single prim is all that is necessary for this example.
 
//  GLOBAL VARIABLES
//  --------------------------------------------------------------
 
float   g_Timer     = 5.0;        //  How fast to change colors (seconds)
integer g_RandomOn  = TRUE;       //  The on/off switch for randomizing
 
//  EVENTS
//  --------------------------------------------------------------
 
default
{
    state_entry()
    {
        //  ------------------------------------------------------
        //  This is the entry-point of the script.  After a script
        //  has been saved or reset, this event will fire off first
        //  ------------------------------------------------------
 
        //  Here we set up a simple timer to fire off once every g_Timer
        //  seconds
        llSetTimerEvent(g_Timer);
    }
 
    touch_start(integer num_detected)
    {
        g_RandomOn = !g_RandomOn;
        if(g_RandomOn) llSetTimerEvent(g_Timer);
        else llSetTimerEvent(0);
    }
 
    timer()
    {
        //  This event is called each g_Timer seconds as declared
        //  previously in the state_entry() event.
 
        //  llSetColor() will change the color of an object taking
        //  vector color and integer face as arguments.  the color
        //  vector is in this form:  where
        //  <0,0,0> = Black and <1,1,1> = White.  In between 0 and 1
        //  is the focus of our different color values, which is why
        //  we use llFrand() to generate a random float number between
        //  0 and 1.  ALL_SIDES is a bit-field global to tell the script
        //  that we want all faces of the object colored -- otherwise
        //  we could specify a particular face to color using the
        //  integer representation of the face.
        vector rand_color = ;
        llSetColor(rand_color, ALL_SIDES);
 
        //  We also want to control the color of the beam.  Since
        //  llSetColor() only affects the object the script is contained
        //  in, we need to send a message to the beam object within the
        //  link set.  The best way to do this is to send a message
        //  using llMessageLinked().  This works much like a listen
        //  command, except the object only talks to other objects
        //  that are linked to it, making it much more secure.
        llMessageLinked(LINK_SET, 1, (string)rand_color, NULL_KEY);
    }
}