Script
A
script is a
Second Life inventory item that contains
LSL code. If a script is placed in a
prim or
object, the script can then control the behavior and appearance of that prim or object, which can cause the prim or object to (among many other things) change
color,
move, interact with the
world, etc. A single prim or object can contain multiple scripts, each one running independently of the others (although they can all have effects on the same prim or object).
A script is edited using the built-in script
editor or external
alternate editors (via cut-and-paste). To see the source
code that makes up a script, if the
user has
permission to view it, simply double-click on its name and the editing window will open up. Each script can have permissions independent of the permissions of an object it is contained in. To be editable, a script must be modifiable by the user, or it could be shared to a
group the user is a member of.
Notes
- A prim or object containing a script being edited doesn't need to actually be selected in order for the script to be edited or updated (after the script window is already open, of course). However, if the scripted prim or object goes "out of range" (the script window's titlebar will say it), any changes to the script will not be saveable until the prim/object comes back in range. A prim or object can go out of range by distance (moving the avatar too far away from the prim or object) or by attachment (where simply "drop"ping the prim/object will bring it back in range, but won't update the script window's titlebar and, if detached, a reattached prim or object's script must be reopened or the current opened script editor window will also give an "out-of-range" error). If the prim or object is lost track of, the script's contents can still be copy-pasted into a new script file.
- If an empty script is dropped into a prim or object, it shouts "Empty script!".
- If a no-copy/no-mod object has a script, and that script is put into another object, the script resets. (explanation)
Internally, each script consists of two items: the script's source code, which is compiled into "
bytecode" by the
client and uploaded to the
simulator. This generates the second item, a 16
kb memory image which is executed in a virtual machine on the sim and contains the script's bytecode,
stack, and
heap. This memory basically represents the current status of the script (not to be confused with its
state) and is saved/restored when the
sim restarts (or when you
attach/detach a scripted object).
Each script receives a
time slice (portion) 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 (section) of memory, preventing scripts from writing into protected simulator memory or into other scripts (which can include multiple scripts in the same prim or object), making it much harder for them to crash the simulator.
Example Scripts
Functions
llGetScriptName - Returns the name of the script that calls the function.
llGetScriptState - Returns TRUE if the script identified by name is running.
llSetScriptState - Changes whether or not the script is running.
llRemoteLoadScriptPin - If permissions and PIN allows, this function will copy a script to a remote object
llSetRemoteScriptAccessPin - Sets the PIN (personal ID number) necessary to remotely load a script.
llScriptDanger - Determines if a position is over land that might disable or delete a script.
llResetScript - Resets all values in a script and restarts it.
llResetOtherScript - Performs
llResetScript on a different, named script.
llGetFreeMemory - Returns the amount of free memory in the script, in bytes.
Resources
Crash Course |
LSL |
Memory |
Object |
Prim |
Item