t he d efault s cript

22
THE DEFAULT SCRIPT F/XUAL EDUCATION SERVICES Investigating States, Events & Functions

Upload: hastin

Post on 24-Feb-2016

34 views

Category:

Documents


0 download

DESCRIPTION

T HE D EFAULT S CRIPT. F/X UAL E DUCATION S ERVICES. Investigating States, Events & Functions. Rez a prim and with it selected display the content tab. Click on the New Script button to create a new script. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: T HE D EFAULT  S CRIPT

THE DEFAULT SCRIPTF/XUAL EDUCATION SERVICESInvestigating States, Events & Functions

Page 2: T HE D EFAULT  S CRIPT

Rez a prim and with it selected display the content tab.

Click on the New Script button to create a new script.

Page 3: T HE D EFAULT  S CRIPT

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.

Page 4: T HE D EFAULT  S CRIPT

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.

Page 5: T HE D EFAULT  S CRIPT

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.

Page 6: T HE D EFAULT  S CRIPT

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.

Page 7: T HE D EFAULT  S CRIPT

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.

Page 8: T HE D EFAULT  S CRIPT

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.

Page 9: T HE D EFAULT  S CRIPT

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).

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.

Page 10: T HE D EFAULT  S CRIPT

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.

Page 11: T HE D EFAULT  S CRIPT

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).

Page 12: T HE D EFAULT  S CRIPT

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.

Page 13: T HE D EFAULT  S CRIPT

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_StartIf 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

Page 14: T HE D EFAULT  S CRIPT

Continue with the script by adding a new FUNCTION into the touch_start EVENT.Place the cursor at the end of line 9.

Page 15: T HE D EFAULT  S CRIPT

Press the Enter key to create a new line.

Page 16: T HE D EFAULT  S CRIPT

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.

Page 17: T HE D EFAULT  S CRIPT

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.

Page 18: T HE D EFAULT  S CRIPT

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.

Page 19: T HE D EFAULT  S CRIPT

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.

Page 20: T HE D EFAULT  S CRIPT

From the Insert button (which will currently display the name of the last item inserted, i.e. llOwnerSay) find and insert the FUNCTION llDetectedName.

Page 21: T HE D EFAULT  S CRIPT

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

Page 22: T HE D EFAULT  S CRIPT

LSL Portal http://wiki.secondlife.com/wiki/LSL_PortalStates http://wiki.secondlife.com/wiki/State

Events http://wiki.secondlife.com/wiki/Category:LSL_EventsFunctions http://wiki.secondlife.com/wiki/Category:LSL_Functions

Types http://wiki.secondlife.com/wiki/Category:LSL_TypesComments http://wiki.secondlife.com/wiki/LSL_101/Comments,_

White-space_and_Formattingstate_entry http://wiki.secondlife.com/wiki/State_entrytouch_start http://wiki.secondlife.com/wiki/Touch_start

llSay http://wiki.secondlife.com/wiki/LlSayllOwnerSay http://wiki.secondlife.com/wiki/LlOwnerSay

llDetectedName http://wiki.secondlife.com/wiki/LlDetectedName

Resources