Second Life Programming | Heaton Research

Second Life Programming

    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 book provides an introduction to LSL. For you to obtain the greatest benefit, I recommend that you have a basic knowledge of "building", but that's not required to understand the book's 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.

    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 Second Life.

    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.

Copyright 2005-2008 by Heaton Research, Inc.