CODE
//==========================================================================
// Luminance Control Test Script
// Original Script By Unknown
// Modifications made by Zanlew Wu 30-Apr-2003
//
//============================================
// Declare global fields.
//
integer gfLtOn; // Used to remember whether the light is on or off.
float gfLtIncr; // Used to hold the lighting increment to adjust with.
//============================================
// gmInitFields()
//
gmInitFields()
{
//
// Set the default state of the lit object.
//
gfLtOn = TRUE;
//
// Set the increment to increase and decrease the lighting level.
//
gfLtIncr = 0.1;
}
//
// End of gmInitFields
//============================================
//============================================
// gmSetColor
//
gmSetColor()
{
//------------------------
// Declare local variables
//
float l; // used for loop control and setting color
vector v; // used to hold a color value
//
// First, check to see if the object is already "lit" or not.
//
if (gfLtOn)
{
//
// Yes, it is lit, so darken it. Do this within a loop.
//
// The loop below basically runs a color-setting loop where the
// the loop variable itself is used as the color increment. From
// what I can gather by seeing it work, color is held in a "vector"
// construct where the three values of the vector represent
// RED, GREEN, and BLUE values. The values apparently can range from
// 0.0 to 1.0 (they are floating point values--as vectors always
// are).
//
// Since this is the area where we darken the light source, I use
// the loop to decrement it's value from 1.0 to 0.0 in steps. The
// size of the step is defined in the field gfLtIncr.
//
for (l = 1.0; l >= 0.0; l = l - gfLtIncr)
{
//
// Now that the value of l has been set, we need to assign
// that color to all the fields of the color vector v. To
// do that, we use direct assignments.
//
// In order to keep the color cycling of the object very
// non-colorful (since it is supposed to be a light source,
// after all), we will adjust all three fields of the vector
// to the same value.
//
v.x = l; // Assign the color value l to the x field of v
v.y = l; // Same, but to y
v.z = l; // "
//
// Now that the color vector is set, assign that vector as the
// color of the object. Instruct the SetColor command to set
// the color to all sides of the object.
//
llSetColor(v, ALL_SIDES);
//
// Now we stay in the loop if we are not at the last color yet,
// or exit the loop if we are at the last color change.
//
}
}
else
{
//
// No, it is not lit, so light it up.
//
// As mentioned before, I use a loop to cycle through the color
// change of the light source. Since this time we are lighting the
// object up, we cycle the loop from 0.0 to 1.0 in gfLtIncr
// increments. Same methdology applies here.
//
for (l = 0.0; l <= 1.0; l = l + gfLtIncr)
{
v.x = l; //
v.y = l; // Same as before
v.z = l; //
llSetColor(v, ALL_SIDES); // Same here too.
}
}
}
//
// End of gmSetColor
//============================================
//============================================
// Default State
//
// This is the state that is automatically bootstrapped when the object
// is first created/rez'd, or the world or environment resets.
//
default
{
//
// state_entry() is the first method executed when the state it resides
// in is run. So State A, B, and C all can have state_entry methods,
// and if they do, they are run when their respective states are called
// and or executed.
//
state_entry()
{
//
// First, initialize the global fields.
//
gmInitFields();
//
// Now set the object to it's default color state.
//
gmSetColor();
}
touch_start(integer total_number)
{
//
// The light has been touched. Now we can switch the state of the
// light to what it is supposed to be.
//
// Since we are using this interger gfLtOn as a boolean, the
// operation of reversing the state of the light from on to off to
// on again can be done with a very simple application of the
// boolean operator ! (not). While I normally like to code the
// long way (the gmSetColor method could have been written more
// efficiently), this is one place I like to take the shortcut.
//
gfLtOn = !gfLtOn;
//
// Now set the color of the light source.
//
gmSetColor();
}
}
edit-just added the code blocks.