Instructables

Getting started in LSL scripting in Second Life

Hello and welcome to "Getting started in LSL scripting". LSL stands for "Linden Scripting Language" and is used to script the objects you will encounter and make in Second Life.

WHO THIS TUTORIAL IS FOR:

This tutorial is intended for those who have never programmed before, Second Life or elswhere. However, this tutorial will make little sense outside of Second Life. LSL is very specific to Second Life.

You will begin by running the standard "hello world" script and eventually move towards making your own. You will need to be familiar the basic principles of Second Life and general building skills before you can make use of everything in this tutorial.

Let's move to step 1. "What is LSL?"
 
Remove these adsRemove these ads by Signing Up

Step 1: What is LSL?

LSL is the Linden Scripting Language. This is the language all scripts in Second LIfe are written in. Its structure is based on Java and C. Scripts in Second Life are a set of instructions that can be placed inside any object in the world, or any object worn by an avatar, but not inside an avatar. They are written with a built-in editor/compiler which we will access in step 2.

One thing that makes LSL unique is it's heavy emphasis on "States" and "Events". A door can be "open" or "closed" and a light can be "on" or "off". A person can be "hyper", "calm", or "bored". Many real life objects have "states" and the same can be true for LSL programs. Minimally a script will have one state, the default state.

An event can be thought of as a "Trigger". Events are not user defined in Second Life but rather predefined in LSL. One called Touch_start(), will trigger the code in it when the object running the script is touched. So the minimum LSL program must have one state with one event in it. Here is a look at a minimal program in written in LSL that can loosely be translated as...."When I am in the default state, and I am touched, say "Hello World" on channel zero".

default
{
touch_start(integer total_number)
{
llSay(0,"Hello World");
}
}

WHAT CAN I DO WITH SCRIPTS?

Scripts can make an object move, listen, talk, operate as a vehicle or weapon, change colour, size or shape. A script can make an object listen to your words as well as talk back to you, scripts even let objects talk to each other.

The most basic object in Second Life is the "Prim" or primitive, the basic building block of all objects you can build in Second Life. When several prims are linked, they can each contain a script which speaks to the rest of the object via Link Messages. These are faster and more private than having objects "chat" or email each other. These are beyond the scope of this tutorial and we will instead focus on single scripts in a single prim.

Scripting is harder to learn than basic object manipulation, but is very rewarding once you make progress.

If you've built in Second Life, everything you can define in the edit window can be defined in a script. All interaction you see between objects or between avatars and objects is via scripts.

Learning more about the world and building model is vital to some aspects of scripting, thus I'd recommend a good foundation in building as you learn to script.
Kia_Anor1 month ago

Can a different script language work in sl for example like : Java,JavaScript, Turbo C and Visual basic?

Koin44410 months ago

I ahve always wished a decent scripter should make some kind of turor app for lsl, something that will teach someone not only to script but understand LSL so someone can begin to truly create scripts.

Just wanted to say thank you for the tut. Trying to find a place to start with all of this is hard, but things like this are certainly helpful. Thanks. Adrianne
maxspawn7 years ago
I saw in a called site www.2lifeblog.com, some scripts to download; Basic Motorcycle Script, animated texture simple, final flight 2.2, and more, also it is possible to download the complete manual of scripting for Sl. Regards: Massimo
maxspawn7 years ago
I saw in a called site www.2lifeblog.com, some scripts to download; Basic Motorcycle Script, animated texture simple, final flight 2.2, and more, also it is possible to download the complete manual of scripting for Sl. Regards: Massimo