LSL 101/Event Handler Parameters

From Second Life Wiki
Jump to navigation Jump to search
← Variable Initialization ↑̲  LSL 101  ̲↑

When we introduced the touch_start event handler, we put off explaining the meaning of what was between the parentheses in this line:

<lsl> touch_start( integer num_detected )</lsl>

The time has come when we can easily explain this. The phrase integer num_detected is a declaration of a local variable that has been created and initialized by the sim server. The server initializes it with the number of distinct touches that have occurred since the last time the touch_start handler was called.

Consider this script:

<lsl>integer TotalTouches = 0;

default {

    touch_start( integer num_detected )
    {
         // Update the total number of touches
         TotalTouches = TotalTouches + num_detected;
         // Announce the current total
         llOwnerSay( "I have been touched a total of " + (string)TotalTouches + " times." );
    }

}</lsl>