Game Development Reference
In-Depth Information
looks simple, this interface has signiicant functionality built into its parts. The Script Editor is a text editor
and a compiler that translates (compiles) the textual symbols we use to write the script into a much more
compact code for the server to run.
14.5 BREAKDOWN: FINDING THE PARTS OF A BASIC SCRIPT
If you look in the Script Editor window, and you have added a new script into an object on a virtual world
running OpenSim, you will see what is shown in the two left-hand columns of Table 14.1. Initially, this writ-
ing probably looks like alien transdimensional driving instructions, but if you take it in bit by bit, so to speak,
it will start to make sense. Remember the movie script sample and how that delineated between what was
going on and who was saying it? That is happening here. In all the script examples shown in Tables 14.1 to 14.5
the actual script is written in the left-hand column and the “plain English” description of what the program is
supposed to do is in the right-hand column for your comparison. Let's examine these two initial scripts from
Second Life and OpenSim, line by line, starting with the one made inside a prim in the OpenSim environment.
14.5.1 a B asiC s CripT in o pen s im
In Table 14.1 is the starting script for an object in OpenSim, broken down by line and deined in plain English
so you can see what those lines of code represent. When you read these scripts, pay close attention to the
curly brackets { } because they enclose important parts of the script and tell the virtual simulation that inter-
prets and runs the script where each section starts and ends.
Line 0 says default . What this means is that the object's script is in its default state when the script
starts. States are the fundamental part of scripting; each object may be in only one state at a time but
may transition through many in the course of running a script, if necessary. With the word default ,
the script is saying to the server, enter the irst state and “start here.” If you look at this script on your
screen, you will see that the text is red. The Script Editor color codes various parts to help identify
them. Default states are always indicated in red.
Line 1 shows the { symbol, which is a curly bracket, and if you follow along in the script editor and
click your mouse cursor on it, it will indicate “Line 1, Column 1” just below the status box. This
bracket encloses all the event handlers, functions and other scripting components that happen when
the script enters its next state, where it will actually begin to do something. Events (and the event
handlers that deal with them) come in many forms; they can be “listen” events that respond to some-
thing in the chat, “sensor” events that respond to avatar proximity, or “collision” events that respond
to something colliding with the object containing that script, to name a few.
TABLE 14.1
A Basic Script in OpenSim
Line No.
Script Code
What It Means in English
0
default
“Start here.”
1
{
This is where we start to have Events and Functions.
2
state_entry()
Event: transition to a new State and wait for instructions.
3
{
This is a new block of code.
4
llSay(0, “Script running”);
Function: say in local chat channel 0, “Script running.”
5
}
This is the end of a block of code.
6
}
All Events and Functions end here, and it is the end of the State.
 
Search WWH ::




Custom Search