Updated for 2025 | 15 Min Read

LSL Scripting Tutorial:
Complete Beginner's Guide

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.

10+ Code Examples
Copy & Paste Ready
Beginner Friendly

What is LSL (Linden Scripting Language)?

LSL is a powerful scripting language designed specifically for virtual worlds. It allows you to:

Create Interactive Objects

Doors that open, weapons that fire, vehicles that drive, games that play

Automate Behaviors

NPCs, security systems, tip jars, greeters, particle generators

Build Dynamic Experiences

Dance floors, light shows, texture changers, animated displays

Design Games & RPGs

Quest systems, scoreboards, inventory managers, combat systems

Why Learn LSL in 2025?

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!

The 3 Building Blocks of LSL

Every LSL script, from simple to complex, is built from these three fundamental concepts

1. States

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.

Real Examples:
• Door: closed / open
• Game: waiting / playing
• Weapon: ready / reloading

2. Events

Events are triggers that activate your code. When something happens (touch, collision, timer), the corresponding event runs automatically.

Common Events:
touch_start - Someone clicks it
timer - Timer goes off
collision - Object bumps into it

3. Functions

Functions are the actions. They tell the object what to DO. You place functions inside events to make things happen in your virtual world.

Popular Functions:
llSay() - Make it talk
llSetColor() - Change color
llMoveToTarget() - Move it
How They Work Together:
STATE (default) → EVENT (touch_start) → FUNCTION (llSay)

Translation: "While in the default state, when a touch event occurs, execute the say function."

Example 1: The Classic "Hello, World!"

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

Before You Start

How to Add a Script to an Object:

  1. Create a prim (Right-Click ground → Create)
  2. Right-click your object → Edit
  3. Click the Content tab in the Edit window
  4. Click New Script
  5. Double-click the script to open the editor
  6. Delete all default text and paste in the code below
  7. Click Save - your script is now running!
// 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!"); } }
Code Breakdown:
  • default { ... }
    This defines the default state. All code inside the curly braces {} belongs to this state.
  • touch_start(integer total_number) { ... }
    This is the touch event. Code here only runs when someone clicks the object. The integer total_number parameter tells you how many avatars touched it (usually 1).
  • llSay(0, "Hello, World!");
    The 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
    Lines starting with // are comments—notes to yourself that the computer ignores. Use them to explain what your code does!
Try It Yourself!

Modify the script to practice:

  • Change "Hello, World!" to your own message
  • Add more llSay() lines to make it say multiple things
  • Change the 0 to 1 to whisper instead of shout

Example 2: A Simple Light Switch

Let'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 } }
New Concepts Introduced:
Variables
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()
state_entry() { ... }

This event runs automatically when entering a state. Perfect for initialization—like turning on a light when you flip the switch.

llSetColor()
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()
llSetText("ON", <1,1,1>, 1.0);

Creates floating text above the object. Parameters: text, color vector, transparency (1.0 = visible, 0.0 = invisible).

Customization Ideas:
  • Change Colors: Try <1.0, 0.0, 0.0> for red, <0.0, 0.0, 1.0> for blue
  • Add Sound: Insert llPlaySound("sound_name", 1.0); in state_entry
  • Make it Glow: Add llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.5]);

Example 3: Rainbow Color Changer (Using Timers)

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."); } }
Key Concepts:
  • llSetTimerEvent(1.0) - Creates repeating timer every 1 second
  • list RAINBOW_COLORS - Stores multiple color vectors
  • % operator - Modulo math wraps index back to 0

Where to Go From Here?

You've learned the fundamentals! Here's how to continue your LSL journey:

Practice Projects
  • Tip jar with llGiveMoney()
  • Teleporter with llSetPos()
  • Rotating sign with llSetRot()
  • Vending machine system
  • Quiz game with scoring
Learning Resources
Community Help
  • Join scripting groups in-world
  • Ask in help chat channels
  • Share scripts with friends
  • Study open-source scripts
  • Attend script workshops

🎓 Ready to Create?

Log into Alife Virtual and start bringing your ideas to life with LSL!

Frequently Asked Questions

No! LSL is designed for beginners. This tutorial assumes zero programming knowledge. If you can follow instructions and think logically, you can learn LSL. Start with simple scripts and build up gradually.

Common causes: 1) Missing semicolons ; 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!

LSL is similar in structure to C and JavaScript but specifically designed for virtual worlds. If you know any programming language, LSL will feel familiar. The syntax is simpler than most languages, making it perfect for learning programming basics.

Yes! Many creators make real money selling scripted objects in Alife Virtual. Popular items include: weapons, vehicles, games, HUDs, animation systems, security systems, and decorative objects. LSL skills are valuable in the virtual economy!

Use 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.