Master Linden Scripting Language (LSL) from scratch! Learn to create interactive objects, automated systems, games, and dynamic content in virtual worlds. No programming experience required.
LSL is a powerful scripting language designed specifically for virtual worlds. It allows you to:
Doors that open, weapons that fire, vehicles that drive, games that play
NPCs, security systems, tip jars, greeters, particle generators
Dance floors, light shows, texture changers, animated displays
Quest systems, scoreboards, inventory managers, combat systems
LSL powers millions of interactive objects across Second Life, OpenSim, and Alife Virtual. It's beginner-friendly, well-documented, and instantly rewarding—you'll see your code come to life in real-time 3D!
Every LSL script, from simple to complex, is built from these three fundamental concepts
A state is a mode of behavior. Think of it like a light switch—it can be "ON" or "OFF". Every script starts in the default state and can switch between different states.
closed / openwaiting / playingready / reloading
Events are triggers that activate your code. When something happens (touch, collision, timer), the corresponding event runs automatically.
touch_start - Someone clicks ittimer - Timer goes offcollision - Object bumps into it
Functions are the actions. They tell the object what to DO. You place functions inside events to make things happen in your virtual world.
llSay() - Make it talkllSetColor() - Change colorllMoveToTarget() - Move it
STATE (default) →
EVENT (touch_start) →
FUNCTION (llSay)
Translation: "While in the default state, when a touch event occurs, execute the say function."
This is the traditional first step in any programming language. We'll make an object say "Hello, World!" when you touch it.
How to Add a Script to an Object:
// My First LSL Script - Hello World!
default
{
// This event runs when someone touches the object
touch_start(integer total_number)
{
// Make the object say something in public chat
llSay(0, "Hello, World!");
// You can add multiple actions:
llSay(0, "You touched me!");
}
}default { ... }{} belongs to this state.
touch_start(integer total_number) { ... }integer total_number parameter tells you how many avatars touched it (usually 1).
llSay(0, "Hello, World!");llSay() function makes the object speak in chat. The 0 means "public chat" (everyone nearby can hear it). The text in quotes is what it says.
// Comments// are comments—notes to yourself that the computer ignores. Use them to explain what your code does!
Modify the script to practice:
llSay() lines to make it say multiple things0 to 1 to whisper instead of shoutLet's build something more interactive! This script makes an object toggle between white ("on") and black ("off") when touched. You'll learn about multiple states and variables.
// Light Switch Script - Toggle ON/OFF
// Define colors as variables (outside any state)
vector COLOR_ON = <1.0, 1.0, 1.0>; // White (RGB: 1,1,1)
vector COLOR_OFF = <0.0, 0.0, 0.0>; // Black (RGB: 0,0,0)
default // This represents the "ON" state
{
// Runs automatically when entering this state
state_entry()
{
llSay(0, "💡 Light is now ON");
llSetColor(COLOR_ON, ALL_SIDES); // Set all faces to white
llSetText("✓ ON (Click to turn OFF)", <1,1,1>, 1.0); // Floating text
}
// When touched, switch to OFF state
touch_start(integer total_number)
{
state off; // Jump to the 'off' state
}
}
state off // Custom state for "OFF" mode
{
state_entry()
{
llSay(0, "🌙 Light is now OFF");
llSetColor(COLOR_OFF, ALL_SIDES); // Set all faces to black
llSetText("✗ OFF (Click to turn ON)", <0.5,0.5,0.5>, 1.0);
}
touch_start(integer total_number)
{
state default; // Return to default (ON) state
}
}vector COLOR_ON = <1,1,1>;
Variables store values you can reuse. vector stores 3 numbers (Red, Green, Blue). Values range from 0.0 (none) to 1.0 (full).
state_entry() { ... }
This event runs automatically when entering a state. Perfect for initialization—like turning on a light when you flip the switch.
llSetColor(COLOR_ON, ALL_SIDES);
Changes the object's color. ALL_SIDES means all faces. You can also specify individual face numbers (0-7).
llSetText("ON", <1,1,1>, 1.0);
Creates floating text above the object. Parameters: text, color vector, transparency (1.0 = visible, 0.0 = invisible).
<1.0, 0.0, 0.0> for red, <0.0, 0.0, 1.0> for bluellPlaySound("sound_name", 1.0); in state_entryllSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.5]);Create a disco light that automatically cycles through rainbow colors! This introduces the powerful timer event.
// Rainbow Color Changer - Automatic cycling colors
integer colorIndex = 0; // Track which color we're on
// List of rainbow colors (Red, Orange, Yellow, Green, Blue, Purple)
list RAINBOW_COLORS = [
<1.0, 0.0, 0.0>, // Red
<1.0, 0.5, 0.0>, // Orange
<1.0, 1.0, 0.0>, // Yellow
<0.0, 1.0, 0.0>, // Green
<0.0, 0.0, 1.0>, // Blue
<0.5, 0.0, 0.5> // Purple
];
default
{
state_entry()
{
llSay(0, "🌈 Rainbow mode activated!");
llSetTimerEvent(1.0); // Fire timer event every 1 second
}
// This event runs every 1 second (set by llSetTimerEvent)
timer()
{
// Get the current color from our list
vector currentColor = llList2Vector(RAINBOW_COLORS, colorIndex);
// Change the object's color
llSetColor(currentColor, ALL_SIDES);
// Move to next color (wraps back to 0 after reaching 5)
colorIndex = (colorIndex + 1) % llGetListLength(RAINBOW_COLORS);
}
// Touch to stop the rainbow effect
touch_start(integer total_number)
{
llSetTimerEvent(0.0); // Stop the timer
llSay(0, "Rainbow stopped.");
}
}llSetTimerEvent(1.0) - Creates repeating timer every 1 secondlist RAINBOW_COLORS - Stores multiple color vectors% operator - Modulo math wraps index back to 0You've learned the fundamentals! Here's how to continue your LSL journey:
Log into Alife Virtual and start bringing your ideas to life with LSL!
; at end of lines, 2) Mismatched curly braces { }, 3) Typos in function names, 4) Using undefined variables. Always check the error message—it tells you the line number!
llOwnerSay("Debug: " + (string)variable); to print values to your chat. Add these throughout your code to track what's happening. Also check the script compile window for syntax errors, and test one feature at a time.