Event driven scripts |
|
| You use LSL to tell the simulator what events to watch for and how to respond to them. Some events, such as touch, are always on the watch list. With others, you have to set up the watch with instructions in the script. | |
| When the event occurs (is raised) the simulator executes the block of code directly following the event in the script. Other code blocks can be nested in this code block. That can make the script hard to read, so it is important to indent nested code blocks if you have to use them. | timer() { ---- -------- -------- } |
| Event managers. These lines carry the
common code used to setup and respond to an event. That includes
global variables, set up code, event trigger, and other code that is not
required but often used with the event. Note that the lines will not
generally be put together in the script. The global variables, for
example, will go at the top. I have used a blank line to separate
lines that would not necessarily be put together in the script.
You could use the code lines here by copying them into your script. I can't guarantee that they are free from typos, but I do mod scripts by copying from these pages. So I think most of them work as copied. Be careful not to miss ending braces and semicolons. |
Links below are to examples of use. |
| key toucher; touch_start(integer total_num) |
Global variable No set up needed for touch. Trigger event code for touch when someone left clicks on the object. Store ID of toucher for later use |
|
integer handle; handle = llListen(0, "", toucher, ""); } listen(integer channel, string name, key id, string msg) |
Global variable Set up for Listen event and store handle for later
use in removing listen |
|
{ llVolumeDetect(TRUE); llMinEventDelay(10.0); }
collision_start(integer num_detected) |
Set intrusion detector. Set delay to avoid double triggering Trigger event code for collision when someone enters the volume of the (usually phantom) object. |
|
{ llSetTimerEvent(seconds); } timer() |
Set timer Trigger event code for timer when specified time has passed. The wait time can be reset within the timer code block. The reset time is often randomzed to vary the time for successive events |
|
on_rez(integer start_param) { Code block to be executed on rez. } |
No set up needed for on-rez. Trigger event code for rez (in the child object) when the object is rezzed by a parent object. Note that this script goes in the child object. |
| { llAllowInventoryDrop(TRUE); } changed(integer mask) |
Set up to let anyone drop (drag and drop) something
into the inventory of the object.
Trigger event when the object's inventory has changed. |
|
The Thinkerer
01/06/2010 Copyright (c) D. F. Dansereau & S. H. Evans |
LODScr | ||
| Famous fables | |||