Getting started in LSL scripting in Second Life by Blueman

Step 6: Introducing States and Events

LSL scripts will not run beginning to end . Instead they will look for a default state and wait for an event. Within those events, there can be a call to go to a new state.

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 adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!