Game Development Reference
In-Depth Information
Line 2 says state _ entry () . This is an event handler, the scripted receiver speciic to an event
that tells the server to execute the commands between the curly brackets { and } of the next text
block. The state_entry () event handler activates when the script runs for the irst time (an event)
or when the script is saved or reset (an event). Please note, in general practice this script element is
simply referred to as an “event,” rather than an event handler. The event color code is blue in the
Script Editor. A state is one of the basic parts of LSL scripting, and a script can only be in one state
at any given time. In this tiny script, there are two states, default , and state_entry . States contain
events by enclosing them with { and } in the structure of LSL.
Line 3 shows {, another curly bracket, but further right in the column. It has been shifted over to indi-
cate to the scripter and to the computer that within this new state, there will be some more things
to do. The curly bracket is saying that these new instructions will happen during this new state and
only while the cube is in this new state.
Line 4 says llSay(0,”Script running”) . This is a function named llSay() , followed by an
indication of what chat channel the cube will announce the message “Script running” on. In this case,
the channel is 0 and is indicated by the irst number (or integer) in the line of code. The color code for
functions is red in the Script Editor. A function is a member of a very large family of commands that
do speciic things in scripts. If you move your mouse down and click on the insert drop-down box
below the status window, you will see a whole list of words starting with ll, and they are all functions
available for use in scripts. Also, note that they have a name llSay() , for instance, and are followed
by (). Note that this line ends with a semicolon, which is required for lines with functions in them.
Line 5 is the } or curly bracket to close the little code block that holds the llSay() function and its
trailing number (or integer) for the chat channel and the string of text it has to say.
Line 6 is } and closes the state within which the cube performs its function of letting us know that the
script is indeed running.
So, to recap what happened: The cube was made, and a new script was added. When that script was added,
it opened in its default state. Then, the cube's script entered a new state, ran a function that made the cube say
that the script inside the cube was running.
14.5.2 a B asiC s CripT in s eCond l ife
Now, for a slightly more complex starting script, let's take a close look at the starting script for a cube made
in Second Life. Refer to the left two columns of Table 14.2.
As you follow along in your on-screen Script Editor looking at a starting script loaded into a cube made in
Second Life, the irst ive lines should look very familiar. The basic start script for Second Life does the same
things as the start script in OpenSim. However, instead of saying “Script running,” it says “Hello, Avatar!”
in the llSay() Function.
After the blank line on line 6, we see something new.
Let's analyze the rest of this script. If the mouse cursor is hovered on the lines while the Script Editor is
open, the Firestorm viewer will give you hints regarding the functionality of each script element and its usage.
Line 7 tells you that this is an event; touch _ start (integer total_number) will activate the follow-
ing function each time the cube is clicked by your mouse, or “touched” (an event).
Line 8 has the curly bracket {, indicating that we will have the start of another block of code in the script.
Line 9 has our old friend the function llSay() followed by the channel number, which is 0 in this
case, and the statement “Touched.” as well as the inal semicolon that ends the line.
Search WWH ::




Custom Search