Step 6: Introducing States and Events
Lets look at a script with two states with two events in each.
The Full Code:
======================
default //default state is manditory
{
state_entry() // runs each time time state is entered
{
llSay(0, "turning on!"); //object speaks!
llSetColor(<1,1,1>, ALL_SIDES); // sets all sides to most bright
// note the semicolons at the end of each instruction.
}
touch_start(integer total_number) // another event with only one function inside
{
state off; // sets the script to a new "state" an starts running "state off"
}
} // this curly bracket ends the body of the default state.
state off // a second state besides "default"
{
state_entry() // this is run as soon as the state is entered
{
llSay(0, "turning off!");
llSetColor(<0,0,0>, ALL_SIDES); // sets all sides as dark as possible
}
touch_start(integer total_number)
{
state default;
}
}
// ---------------end of code ----------------
A simplification of this would be
default
{
//set color to light and, if touched, enter the "off" state.
}
state off
{
//set color to dark and, if touched, enter the "default" state.
}
Note that after "default" all new states begin with the word "state". Also, while the object has a texture, the color will effect the "tint" more than the true color.
Remove these ads by
Signing Up
















Not Nice














Visit Our Store »
Go Pro Today »



