Difference between revisions of "LSL 101/Event Handler Parameters"

From Second Life Wiki
Jump to navigation Jump to search
(New page: Category:LSL 101 {{NavNextPrev|prev=Variable Initialization|next=}} When we previously introduced event handlers, we put off explaining the meaning of what was between the paren...)
 
Line 2: Line 2:
{{NavNextPrev|prev=Variable Initialization|next=}}
{{NavNextPrev|prev=Variable Initialization|next=}}


When we previously introduced [[event handlers]], we put off explaining the meaning of what was between  
When we introduced the [[LSL 101/The touch_start Event|touch_start event handler]], we put off explaining the meaning of what was between the parentheses in this line:
 
the parentheses in this line:


<lsl> touch_start( integer num_detected )</lsl>
<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  
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.


of a local variable.
Consider this script:


Consider this script:
<lsl>integer TotalTouches = 0;


default
default
Line 18: Line 16:
     touch_start( integer num_detected )
     touch_start( integer num_detected )
     {
     {
           // Announce the region where the script is running
           // Update the total number of touches
           string TextPhrase;
           TotalTouches = TotalTouches + num_detected;
           TextPhrase = "I was just touched " + (string)num_detected  + " time.";
 
          llOwnerSay(  );
          // Announce the current total
           llOwnerSay( "I have been touched a total of " + (string)TotalTouches + " times." );
     }
     }
}</lsl>
}</lsl>

Revision as of 22:26, 2 June 2009

← 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>