2. Rez a prim and with it selected
display the Content tab.
Click on the New Script button to
create a new script.
3. Right click on the New Script icon
and select Rename from the menu.
Rename the script appropriately.
Right click on the script icon and
select Open from the menu OR
double click on the icon to open the
script.
4. The default script is displayed when the new script is opened.
Note that when the script was created the text Hello, Avatar! was displayed in main chat. Lines 2 to 5
show the EVENT that was triggered when the script was created (loaded into the prim). Line 4 is the
FUNCTION that generated the chat.
5. Scripts are comprised of STATES, the main state being the default state. This state is entered when a script
is compiled (saved), reset or loaded. More than one state may be defined, though one is the norm.
A script will react to EVENTS in the current state which are triggered by some occurrence or input, which
in turn run the FUNCTIONS defined in that event. Functions can be either the built-in functions of LSL or
user-defined functions. Curly brackets, i.e. { }, enclose the contents of a STATE or EVENT.
6. EVENTS may have built in parameters though the state_entry EVENT has none. This event is triggered when the
script is saved, when a STATE has been changed, when the script is reset or when the script is loaded into a prim.
The touch_start EVENT has one parameter, which is of the data type INTEGER (whole number). This event is
triggered when the prim is touched (clicked on by the down press of the left mouse button). The parameter
indicates the total number of avatars touching the prim during the last computing clock cycle.
7. Most FUNCTIONS also have built in parameters. The llSay FUNCTION has two, the first being the data type
INTEGER and the second the data type STRING. A string is text data and is contained between double quotes. Any
character can be used in a string.
All data types in LSL are immutable and built in parameters must be included in the EVENTS or FUNCTIONS.
The data types in LSL are; FLOAT, INTEGER, KEY, LIST, ROTATION, STRING and VECTOR.
8. To change the text generated by the llSay FUNCTION select the text between the double quotes in Line 4.
This parameter is the data type STRING and will be the text that is said when this function runs.
9. In the above example the text has been changed to Good morning Isa! To save the changes click on the
Save button (which is now highlighted due to some portion of the script being changed) OR press Ctrl S.
The script will be saved (compiled). This will trigger the state_entry EVENT which will run all the parts of
the script between the curly brackets { } from line 3 to 5. In this case it is the llSay FUNCTION that runs and
displays the text Good morning Isa! in main chat.
10. Every time a script is saved the state_entry EVENT is triggered. This will cause the llSay FUNCTION on line
4 to run. To prevent this happening it is possible to COMMENT out the function by placing two forward
slashes at the beginning of the line. This leaves the line visible in the script but does not compile this part
of the script when it is saved. Click on the Save button and you will see this function no longer runs.
Comments are a useful way of adding notes to remind you of the function of certain sections of code.
11. Help pop-ups can be accessed for all aspects of a script. For example holding the cursor over the
touch_start EVENT shows the pop-up above indicating that this event has one parameter, an INTEGER,
and that the event is triggered by the start (pressing the left mouse down) of agent (avatar) clicking on
task (the prim).
12. FUNCTIONS also have help pop-ups. In this example the llSay FUNCTION is shown to have two
parameters, an INTEGER and a STRING. When run the llSay FUNCTION will say the text of the STRING on
the chat channel indicated by the INTEGER. In this case the text Touched. will be said on channel 0, this
being the main public chat channel. A touch_start EVENT can only be tested with the prim deselected. A
script can be left open, altered and saved even when the prim is deselected. Test the touch_start EVENT.
13. LSL scripting syntax is very strict.
STATES and EVENTS must be enclosed in curly brackets { } and
lines of code within an EVENT must end with a semi-colon ;
All built in parameters must be included in EVENTS and
FUNCTIONS and must be enclosed in parentheses ( ), each of the
parameters must be delimited by a comma , and be in the correct
order and data types must be correct.
Code is also case sensitive so the correct case must be adhered
to, e.g. llSay not LLsay and touch_start not Touch_Start
If these rules are not met an error will occur when the script is
compiled (saved). The compiler will pause the cursor in the
vicinity of the error, usually the line after it occurs, so this is a
good indication of where the error is.
Linden Scripting Language SYNTAX
14. Continue with the script by adding a new FUNCTION into the touch_start EVENT.
Place the cursor at the end of line 9.
16. All EVENTS and FUNCTIONS can be accessed through the Insert button (though the newest additions to
LSL may take a little while becoming available in this menu). In this example the FUNCTION llOwnerSay
will be inserted. Click on the Insert button and scroll down the list till you see this function. Click on it to
insert it in the script.
17. As seen on line 10 the llOwnerSay FUNCTION has been inserted. Hold the cursor over the function to
display the help pop-up. This function has one parameter, a STRING. This string’s text will be said only to
the owner of the prim the script is in and the owner must be in the same sim as the prim to hear it.
The text will appear in the main chat window but will only be seen by the prim owner.
18. Complete the FUNCTION by adding parentheses ( ) and writing the STRING of text you wish to be seen
inside them. Ensure the text has double quotes around it, e.g. “Isa touched me”. Also ensure that the line
has been concluded with a semi-colon ; The line should look like: llOwnerSay(“Isa touched me”);
Comment out line 9 so that only the llOwnerSay function runs when the touch_start EVENT is triggered.
Click on the Save button to compile the script. Test the script by touching the prim.
19. It is also possible to add a FUNCTION within another FUNCTION. Currently the llOwnerSay FUNCTION in
the touch_start EVENT only says the text Isa touched me but doesn’t indicate who really touched the
prim. Anyone touching the prim will trigger this text to display. That can be changed.
Place the cursor after the first parenthesis in line 10 as shown above.
20. From the Insert button (which will currently display the name of the last item inserted, i.e. llOwnerSay)
find and insert the FUNCTION llDetectedName.
21. The FUNCTION llDetectedName has one parameter, an INTEGER, which accesses the list of avatars who
touched the prim. (This list is created by the touch_start EVENT.) Complete the script as shown in line 10.
The parameter 0 used in the llDetectedName FUNCTION accesses the first name in the list. It is extremely
unlikely that more than one avatar will touch a prim in one clock cycle so the first name suffices. Now save
the script and test the result. The text in chat will now say SomeAvatarName touched me