Intro to LSL Scripting

Ready to bring your creations to life? The Linden Scripting Language (LSL) is how you make objects interactive. This guide will walk you through the absolute basics.

The Three Building Blocks of a Script

Every script, no matter how complex, is built from three fundamental concepts.

States

A state is a mode of behavior. An object can be in an "on" state or an "off" state. A door can be "open" or "closed." Every script starts in the `default` state.

Events

Events are triggers. When someone touches an object (`touch_start`), a timer goes off (`timer`), or the object collides with something (`collision`), an event runs.

Functions

Functions are the actions. `llSay()` makes an object talk. `llSetColor()` changes its color. `llDie()` deletes the object. You use functions inside events to make things happen.

Example 1: The Classic "Hello, World!"

This is the traditional first step in any programming language. We'll make a prim say "Hello, World!" when you touch it.

  1. Create a prim (Right-Click ground > Create).
  2. In the Edit window, go to the `Content` tab.
  3. Click `New Script`, delete the default text, and paste this in:
default { touch_start(integer total_number) { llSay(0, "Hello, World!"); } }
What's Happening Here?

Example 2: A Simple Light Switch

Let's make something more useful. This script will make a prim toggle between white ("on") and black ("off") when touched. This will teach you how to use multiple states and store information in a variable.

// Define colors to use later. This part is outside of any state. vector COLOR_ON = <1.0, 1.0, 1.0>; // White vector COLOR_OFF = <0.0, 0.0, 0.0>; // Black default // This will be our "ON" state { state_entry() { llSay(0, "Light is now ON."); llSetColor(COLOR_ON, ALL_SIDES); // Set the color to white } touch_start(integer total_number) { state off; // When touched, switch to the 'off' state } } state off { state_entry() { llSay(0, "Light is now OFF."); llSetColor(COLOR_OFF, ALL_SIDES); // Set the color to black } touch_start(integer total_number) { state default; // When touched, switch back to the 'default' (ON) state } }
New Concepts in This Script:

Where to Go From Here?

You've learned the most important concepts! The best way to learn now is to experiment.

Suggestions for New Content and Images

To Make This Guide Even Better: