Handling Events
The last section showed how the touch_start function is called whenever an avatar touches an object. The touch_start function is an event handler. Second Life includes many different event handlers. The recipes in this book make use of many of these event handlers.
There are currently a total of 34 different event handlers in the Linden Scripting Language. Appendix C, “Event Types” provides a listing of all of the event types in the Linden Scripting Language.
Another very common event type is the timer event. Many of the recipes in this book use timer events. The following script uses timer events.
default
{
state_entry()
{
llSetTimerEvent(1);
}
touch_start(integer total_number)
{
llSetTimerEvent(0);
}
timer()
{
llSay(0,"Timer");
}
}The above script starts with a state_entry event handler. The state_entry event handler is called when the object enters the state associated with the event handler. In this case, the state_entry event handler is called when the default state is entered.
The provided state_entry event handler begins by calling the llSetTimerEvent function to establish a timer. The parameter passed to the llSetTimerEvent function call specifies the number of seconds between timer events. To disable the timer call the llSetTimerEvent function with a value of zero.
Every time a timer event occurs, the timer event handler is called. The above script says “Timer” each time that the timer event occurs.












