Alife Virtual Metaverse social network Linden Scripting Language

Step into the Metaverse with Alife Virtual and experience the an social network universe like never before. The Linden Scripting Language (LSL) is a programming language used for scripting the behavior of objects within Alife Virtual and Second Life, the most expansive online virtual worlds metaverse games. Designed by Linden Lab, LSL allows users, from hobbyists to professionals, to add interactivity and dynamic behavior to their creations, making the virtual experience more immersive and engaging.

Why Learn LSL?

Learning LSL opens up a world of creativity and opportunity within Alife Virtual and Second Life. With LSL, you can create:

Interactive Objects: Make objects that users can interact with in various ways.

Games: Design your own games to be played within world.

Simulations: Create simulations for educational or entertainment purposes.

Automations: Automate tasks and processes within your virtual space.

Installations: Build dynamic art installations that respond to user input.

Getting Started with LSL

To begin scripting in LSL, you'll need a basic understanding of programming concepts. However, LSL is relatively easy to learn, especially for those with some programming experience. Here's how to get started:

Log in to Alife Virtual and get a cheap land (starting at 1 C$) where you can create objects.

Create a new object by right-clicking on the ground and selecting Create.

Right-click the object and select Edit, then go to the Content tab.

Click New Script to add a new script to the object. This will open the LSL editor.

You can now start scripting! A simple script to make your object say "Hello, World!" when touched would look like this:

touch_start(integer total_number)
llSay(0, "Hello, World!");

Save your script and close the editor. Your object is now ready to respond to touch events!

The code above contains 1 state, 2 events, and 2 functions. Any line starting with two forward slashes // is a comment. It will not run and is used to help you document your code. Let's look at them individually.


A state is a set of instructions that define the behavior of an object. In the example above, the state is default. The default state is the initial state of an object when the script is first run. Any script must have at least one default state, and it can have multiple states to handle different behaviors.

default //default state is mandatory { state_entry() // runs each time the state is entered { llSay(0, "turning on!"); //object speaks! llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES); // sets no tint (white) // note the semicolons at the end of each instruction // (do not put them at the end of "if" statements) } // Note: for technical reasons discussed elsewhere, we use a touch_end event rather than touch_start when state changes are involved touch_end(integer total_number) // another event with only one function inside { state off; // sets the script to a new "state" and 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.0, 0.0>, ALL_SIDES); // sets black tint } touch_end(integer total_number) { state default; } }

Events are actions that trigger specific behaviors in the script. In the example above, the events are touch_start. The touch_start event is triggered when the object is touched by an avatar. There are many other events in LSL that can be used to create interactive experiences.


Functions are predefined blocks of code that perform specific tasks. In the example above, the function is llSay. The llSay function is used to display a message in the chat window of the avatar who touched the object. LSL provides a wide range of functions that can be used to manipulate objects, interact with users, and more.

Advanced LSL Scripting

Once you're comfortable with the basics of LSL, you can start exploring more advanced scripting techniques to create complex and interactive experiences. Here are some advanced concepts you can learn:

Variables: Use variables to store and manipulate data within your scripts.

Loops: Create loops to repeat a set of instructions multiple times.

Conditions: Use conditional statements to make decisions based on specific conditions.

Functions: Define your own functions to reuse code and make your scripts more modular.

Events: Explore different events to trigger behaviors based on user actions or system events.

Physics: Enable physics for objects to create realistic movements and interactions.

Collisions: Detect collisions between objects and respond accordingly.

Sound: Play sounds to enhance the immersive experience of your creations.

Animations: Create animations to bring life to your objects and avatars.

Networking: Communicate with external servers or other objects in the virtual world.

Example Advanced Script

Here's an example of a script that creates a bouncing ball:

vector velocity = <0, 0, 1>; // Initial velocity of the ball
float speed = 1.0; // Speed of the ball
float gravity = -0.1; // Gravity force applied to the ball
float radius = 0.5; // Radius of the ball
integer bounceCount = 0; // Number of times the ball has bounced
integer maxBounces = 5; // Maximum number of bounces
integer collisionSound = 12345; // Sound ID for the collision sound
integer collisionVolume = 1; // Volume of the collision sound
integer collisionRadius = 2; // Radius within which the ball detects collisions
llSetStatus(STATUS_PHYSICS, TRUE); // Enable physics for the object
collision_start(integer num_detected)
if (num_detected > 0)
vector normal = llDetectedNormal(0); // Get the surface normal of the collision
velocity = llReflect(velocity, normal); // Reflect the velocity based on the surface normal
velocity *= speed; // Apply the speed to the reflected velocity
llPlaySound(collisionSound, collisionVolume); // Play the collision sound
bounceCount++; // Increment the bounce count
if (bounceCount >= maxBounces)
llDie(); // Destroy the object if it has reached the maximum number of bounces
touch_start(integer total_number)
llSay(0, "Hello, World!"); // Display a message when the ball is touched

This script creates a ball that bounces when it collides with other objects. Here's a breakdown of each line:

  • default: The default event handler for the script.
  • vector velocity = <0, 0, 1>;: Defines the initial velocity of the ball.
  • float speed = 1.0;: Sets the speed of the ball.
  • float gravity = -0.1;: Defines the force of gravity applied to the ball.
  • float radius = 0.5;: Sets the radius of the ball.
  • integer bounceCount = 0;: Keeps track of the number of times the ball has bounced.
  • integer maxBounces = 5;: Defines the maximum number of bounces allowed.
  • integer collisionSound = 12345;: Specifies the sound ID for the collision sound.
  • integer collisionVolume = 1;: Sets the volume of the collision sound.
  • integer collisionRadius = 2;: Defines the radius within which the ball detects collisions.
  • state_entry(): The event triggered when the script enters the default state.
  • llSetStatus(STATUS_PHYSICS, TRUE);: Enables physics for the object.
  • collision_start(integer num_detected): The event triggered when a collision is detected.
  • llDetectedNormal(0): Retrieves the surface normal of the collision.
  • llReflect(velocity, normal): Reflects the velocity based on the surface normal.
  • llPlaySound(collisionSound, collisionVolume): Plays the collision sound.
  • llDie(): Destroys the object if it has reached the maximum number of bounces.
  • touch_start(integer total_number): The event triggered when the ball is touched.
  • llSay(0, "Hello, World!");: Displays a message when the ball is touched.

The Linden Scripting Language is a powerful tool for creators in the virtual world of Alife Virtual. Whether you're looking to bring your imaginative concepts to life, create engaging games, or automate tasks, LSL provides the means to make it happen. With resources and a supportive community at your disposal, diving into LSL scripting is both rewarding and fun. Start scripting today and unlock the full potential of your creativity in the virtual world!