Creating a Script | Heaton Research

Creating a Script

    Second Life scripts are contained in prims. Each prim can contain one or more scripts. To create a simple script, rez a cube onto the ground. Edit the cube and select the “Content” tab. If you do not see the “Content” tab, select the “More>>>” button. The Content tab shows all of the items contained inside of the box. Prims can contain many different types of objects. Prims can also contain other prims.

    Prims usually contain scripts and other objects useful to those scripts. For example, an automobile may contain a script to run the car. The automobile might also contain sounds to play when the car is started or shut off. To create a new script in the box that was just rezzed, select the “New Script...” button. This will add a script named “New Script” to the content pane. This script can be seen in Figure 2.1.

Figure 2.1: A New Script

A New Script

    To edit the script, double click the new script. This will open the script editor. The script editor can be seen in Figure 2.2.

Figure 2.2: The Script Editor

The Script Editor

    Whenever a new script is created a “generic script” is placed inside of the script. This “generic script” can be seen in Figure 2.2. This is the starting point for all scripts created in Second Life. One of the first things to notice about the script, shown in Figure 2.2, is the use of curly braces. Second Life scripts are broken into blocks of code. These blocks begin with an opening curly brace ( { ) and end with a closing curly brace ( } ).

    A block of code can contain other blocks of code. For example, Figure 2.2 shows a block of code named default. The word “default” appears just before the opening curly brace. Inside of the default block of code there are two other blocks of code. The first is named state_entry. The second is named touch_start. There isMark Biss2007-12-11T00:00:00Singular ? refers to the "total", not the three blocks a total of three blocks of code. The default block of code contains the other two blocks of code.

    Blocks of code group the code contained within them together. The default block of code defines one state of the script. Scripts in Second Life are implemented as state machines. Scripts begin in the default state and each script must provide a default state. .Scripts are not required to contain any state other than the default state. For the script shown in Figure 2.2 there is only the default state. State machines will be covered in Chapter 3.

Copyright 2005-2008 by Heaton Research, Inc.