Secondlife Blog
 
  • English
  • Spanish
  HOME arrow SL SCRIPTING GUIDE
Bookmark Website    Bookmark Page 
HOME
2LIFE NEWS
News From Reuters
SL Games
SEARCH
SL SCRIPTING GUIDE
SL Scripts Downloads
INTEREST SITES
CONTACT US
exchange marketplace
seconlife videos
Secondlife Blogs
Who's Online
 
We have 17 guests online
mod_vvisit_counterToday76
mod_vvisit_counterYesterday986
Who's Online


 Subscribe in a reader










Scripts Download
File Icon Texture Menu Management (1230)
File Icon Email to IM (898)
File Icon Code Racer (768)
File Icon Chat Logger (927)
File Icon Builders Buddy (1083)
File Icon Binary Clock (944)
File Icon Overriding Pose Ball (967)
File Icon Scan Ball (1009)
File Icon 3D Radar (1084)
File Icon Teleport Script (2281)
File Icon Super Jump Script (1724)
File Icon SetText Rotating Banner (1519)
File Icon Particle engine 1.0 (1843)
File Icon JetPack Script (2119)
File Icon Follow Camera (1480)
SL SCRIPTING GUIDE

01 - Introduction

SL Scripting Guide
Written by Linden Lab   
jueves, 10 mayo 2007

The Linden Scripting Language (LSL) is a simple, powerful language used to attach behaviors to the objects
found in Second Life . It follows the familiar syntax of a c/Java style language, with an implicit state machine for
every script.


Multiple scripts may also be attached to the same object, allowing a style of small, single-function scripts to
evolve. This leads to scripts that perform specific functions ("hover", "follow", etc.) and allows them to be
combined to form new behaviors.


The text of the script is compiled into an executable byte code, much like Java. This byte code is then run within
a virtual machine on the simulator. Each script receives a time slice of the total simulator time allocated to
scripts, so a simulator with many scripts would allow each individual script less time rather than degrading its
own performance. In addition, each script executes within its own chunk of memory, preventing scripts from
writing into protected simulator memory or into other scripts, making it much harder for scripts to crash the
simulator.


This tutorial introduces the reader to the basic features of LSL, how to edit and apply your scripts, and a
complete reference for standard linden constants, events, and library functions.

Last Updated ( viernes, 13 julio 2007 )
 

02 - Getting Started

SL Scripting Guide
Written by Linden Lab   
jueves, 10 mayo 2007

You’re probably wondering what you can do with LSL, and how quickly you can do it. We’ll start with some simple examples, disect them, and introduce you the the script development process while we’re at it.


2.1. Hello Avatar


Continuing a long tradition of getting started by looking at a script that says "Hello", we’ll do just that. Though obviously not a particularly useful example on it’s own, this example will introduce us to:

 

• Creating a basic script
• Script states
• Calling functions
• Script events
• Applying a script to an object


2.1.1. Creating the Script


Start by opening your inventory and selecting ’Create|New Script’ from the inventory pull down menu. This wil create an empty script called ’New Script’ in your ’Scripts’ folder. Double click on the text or icon of the script to open the script in the built in editor. When you open the script, the viewer will automatically insert a basic skeleton for lsl. It should look like:

 

default
{
        state_entry()
        {
            llSay(0, "Hello, Avatar!");
        }
        touch_start(integer total_number)
        {
            llSay(0, "Touched.");
        }
}


A casual inspection of this script reveals that this scipt probably says ’Hello, Avatar!’ when it enters some state, and it says ’Touched.’ when it is touched. But since this is also probably the first time you have seen a script we’ll disect this short listing, explaining each segment individually.


2.1.2. Default State

 

default
{
...
}


All LSL scripts have a simple implicit state machine with one or more states. All scripts must have a default state, so iff there is only one state, it will be the ’default’ state. When a script is first started or reset, it will start out in the default state.


The default state is declared by placing the default at the root level of the document, and marking the beginning with an open brace ’{’ and ending with a close brace ’}’. Because of it’s privileged status, you do not declare that it is fact a state like you normally would with other states.


Every time you enter a state, the script engine will automatically call the state_entry() event and execute the code found there. On state exit, the script engine will automatically call the state_exit() event before calling the next state’s state_entry handler. In our example, we call the llSay() function in state_entry() and do not bother to define a state_exit() handler. the state entry and exit handlers are a convenient place to initialize state data and clean up state specific data such as listen event callback.


You can read more about the default state, and how to create and utilize other states in the states chapter.


2.1.3. Functions


The language comes with well over 200 built in functions which allow scripts and objects to interact with their enviornment. All of the built in functions start with ’ll’.


The example calls the ’llSay()’ function twice. llSay() is used to emit text on the specified channel.
llSay( integer channel string text );


Say text on channel. Channel 0 is the public chat channel that all avatars see as chat text. Channels 1 to 2,147,483,648 are private channels that aren’t sent to avatars but other scripts can listen for.


You can define your own functions as long as the name does not conflict with a reserved word, built in constant, or built in function.

 

2.1.4. Touch Event

 

touch_start(integer total_number)
{
llSay(0, "Touched.");
}


There are many events that can be detected in your scripts by declaring a handler. The touch_start() event is raised when a user touches the object through the user interface.


2.1.5. Try it Out


Now that we have seen the default script, and examined it in some detail, it is time to to see the script in action.
Save the script by clicking on Save. During the save process, the editor will save the text of the script and compile the script into bytecode and then save that. When you see message ’Compile successful!’ in the preview window, you know the compile and save is done.


To test the script you will have to apply it to an object in the world. Create a new object in the world by context clicking in the main world view and selecting Create. When the wand appears, you can create a simple primitive by clicking in the world. Once the object appears, you can drag your newly created script onto the object to start the script.


Soon after dragging the script onto the object, you will see the message Object: Hello Avatar!
Make sure the touch event is working by clicking on the object. You should see the message Touched printed into the chat history.


2.2. Using The Built-In Editor


The built in editor comes with most of the typical features you would expect from a basic text editor. Highlight text with the mouse, or by holding down the shift key while using the arrow keys. You can cut, copy, paste, and delete your selection using the ’Edit’ pull down menu or by pressing the usual shortcut key.


2.3. Using Alternative Editors


Since the built-in editor supports pasting text from the clipboard, you can employ a different editor to edit your scripts, copying them into Second Life when you’re ready to save them.

Last Updated ( jueves, 12 julio 2007 )
 
More...
<< Start < Prev 1 2 3 Next > End >>

Results 1 - 3 of 9
Related Items
HOME | 2LIFE NEWS | News From Reuters | SL Games | SEARCH | SL SCRIPTING GUIDE | SL Scripts Downloads | INTEREST SITES | CONTACT US | exchange marketplace | seconlife videos | Secondlife Blogs |
Advertisement
login





Lost Password?
No account yet?
Register
Friendly Webs

   
© 2013 2lifeBlog
Second Life® and Linden Lab® are trademarks or registered trademarks of Linden Research, Inc.
All rights reserved. No infringement is intended.