RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Programming Second Life with the Linden Scripting Language

If you learned programming in your first life, you can now exercise your skills in Second Life, using Linden Scripting Language to activate objects you build in the popular simulation.

econd Life (SL) is an extremely popular, massively-multiplayer online game (MMOG) produced by Linden Labs. Many consider Second Life to be much more than a game. If you're unfamiliar with Second Life, it's a little like the movie "The Matrix," in which people live and work in a simulation of the world around them. Second Life is very similar; your computer player, called an avatar, lives in Second Life's 3D world.

There is no specific objective to Second Life, what happens there depends entirely on what you want to make of it. Additionally, Second Life is free to play. You do have to register, but you only have to subscribe if you want to own land.

However, unlike "The Matrix," current computer technology is not advanced enough to comprehensively simulate a physical world, so Second Life has two important shortcomings. First, you see the world of Second Life through a computer screen, which—even though it uses state-of-the-art 3D graphics—gives the simulation a somewhat cartoonish look. Despite that, many areas in Second Life are visually stunning.

Second, the simulation of Second Life is not a complete physical simulation. Important elements, such as gravity, are present. However, you could not completely simulate something as complex as an automobile in Second Life, it's simply still too difficult to simulate all the aspects of the internal combustion engine and electrical components of a car. Modern computers are just not powerful enough to do this. Still, there are cars and many other sorts of vehicles in Second Life, as you'll see in this article.

You access Second Life through a free client that's available for a wide variety of OSs, including Windows, Macintosh, and UNIX. Additionally, Linden Labs recently released the client as open source, which opens Second Life for third-party developers to create a wide range of additions to and enhancements for the Second Life client.

Introducing Linden Scripting Language
Second Life provides a scripting programming language called the Linden Scripting Language (LSL) to fill in the gaps left by Second Life's simple physics engine. Rather than simulate every aspect of a car, a programmer creates a script that tells the car how it should move. This script can play sounds, turn the car, and even detect collisions. For example, to add realism, a car script could prevent the car from turning when not in motion.

This article provides an introduction to LSL. For the greatest benefit, I recommend that you have a basic knowledge of "building," but that's not required to understand the article code. Building is the process by which you place 3D primitives into the Second Life world. Builders have created everything that you see in Second Life.

This article assumes you are already somewhat familiar with the building process in Second Life. It is not terribly difficult to build simple objects in Second Life, but you do have to be "in" Second Life to build things. To try it out, simply click the "Build" button at the bottom of your Second Life window and begin experimenting.

LSL Basics
The Linden Scripting Language looks much like C at first glance. However, it is much easier to program than C. There are no pointers and you can do direct string comparisons without using functions such as strcmp. LSL is not object-oriented; you cannot create your own objects, and the language provides only a few 3D-related objects for you. LSL is state based. Every LSL script has a specific state and carries out its functions by moving through a series of states. This is quite a different concept from most programming languages. While you can build state machines in most languages, in LSL the concept of a state machine is inherently part of the language.

LSL scripts reside inside 3D primitives in Second Life. Objects are collections of primitives. For example, a car in Second Life would be a single object. However, the car object would be made up of many primitives, each of which may contain its own script. Additionally, these primitives can communicate with each other or even with human players. With more advanced programming primitives can even communicate with web pages external to SL.

LSL is also event driven. Most objects in Second Life work by progressing through states driven by events. Second Life provides many different event types. Most are user-based, such as when a user touches or sits on an object; however, it also supports timer events that require no user interaction.

In the rest of this article, I'll show you how to activate an elevator in Second Life.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date