3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Getting started in LSL scripting in Second Life

Step 6Introducing 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.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
4
Followers
1
Author:Blueman
Hey all, this is Blueman Steele. I don't log in much now but want to try to put some of the many things I learned in Second Life here on this site.