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 4A Closer Look

Lets take a look at the deafult code.

// Code start
default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}

touch_start(integer total_number)
{
llSay(0, "Touched.");
}
}
// Code end

The code above contains 2 comments, 1 state, 2 events and 2 functions. Lets look at them individualy.

COMMENTS

Any line starting with two forward slashes is a comment. It will not run and is used to help you document your code.

// This is a comment

STATES

A "State" in LSL is a section that is running, and waiting for events. Only one state can be active at any one time per script. Every script must have a default state with at least one event in it. Except for the default state, each state is define by the word STATE followed by the name of the state. The contents of the state are enclosed in two curly brackets.

default
{
// contents of state go here
}

state playing
{
// this is a state called "playing"
}


EVENTS

Events are inside of states. By "inside" I mean it is between the open and closed curly brackets that represent the body of the state. When that state is active, those events wait to be triggered and run the code inside them. We've seen "state_entry" which is trigged by the a state being entered, and "touch_start" which is triggered when you, or anyone, touches an object.

Lets take a look at the deafult code.

// Code start
default
{
touch_start(integer total_number) // this is an event
{
// this is the content of the event
}
// end of event
}
// end of state


FUNCTIONS

Functions lay inside of events and are either defined by you or built-in. Those built in to LSL all start with two lower case L's. We've seen llSay() so far. Functions take "arguments" or values in the parentheses that follow it. If you hover over the function in the editor, a popup will show that tell you what the function is expecting. In the case of llSay it expects a number and a string. We send it the number zero and the string "Hello, Avatar!" separated by commas. The function is "expecting" a number and strings and won't take anything else.
« 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.