EVENTS AND EVENT HANDLERS
LSL is an event-driven language. This behavior is a major discriminating feature between LSL and many
other languages. Essentially, the script's flow is determined by events such as receiving messages from other
objects or avatars, or receiving sensor signals. Functionally, events are messages that are sent by a Second
Life server to the scripts active in that sim. Event messages can be received by defining the matching event
handlersJOUIFTUBUFTPGZPVSTDSJQUTNothing happens in a script without event handlers: even the passing
of time is marked by the delivery of timer events. Some events cannot happen without the matching event
a script with a money() event handler, avatars cannot pay that object.
Many library functions have effects that take relatively long periods of time to accomplish. Rather
than blockingTUPQQJOHFYFDVUJPO-4-VTFTasynchronous communications: your script fires off a request
that something happen, and it is notified with an event when the request is satisfied. This pattern is used
instance, the function llHTTPRequest() and the http_response() event handler), when physical
TJNVMBUJPOFGGFDUTBSFOhUHPJOHUPCFJOTUBOUBOFPVTllTarget() and at_target()). You could also
UIJOLPGSFQFBUJOHFWFOUTllSensorRepeat() and sensor()PSFWFOMJTUFOFSTllListen()
and listen()) as following the same model: make a request and get responses later. This model of
asynchronous execution allows your script to keep functioning, handling other events and interactions
without stopping to wait for long-term requests to happen.
for execution by the script in the order they were raised. You should be aware of several important
constraints on the delivery of event messages to handlers:
this with llMinEventDelay(float seconds) but it can not be less than 0.05 second.
The combination of these factors means that if you have code that expects to get events rapidly and
happen as often as every 0.1 second) is probably asking for trouble.
Similarly, the LSL function llSleep(float seconds) pauses script execution for the specified
number of seconds without leaving the current event handler, similar to the way that many LSL functions
introduce artificial delays. In both cases, there is a potential problem if your script is likely to handle lots
Some events are delivered to a script only if the script has made the appropriate request. For
instance, a listen() event handler is never called unless another handler in the same state has called
llListen(). The SYW website has a list of all the LSL event handlers, the functions required to enable
the event, and the Second Life situation that results in that raised event. And, of course, there are lots of
examples throughout the book.