Difference between revisions of "LSL 101/The touch start Event"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 25: Line 25:
If a user clicks on your object many times, the touch_start event handler code will generally get executed many times, once for each click.  But if multiple users click on your object at approximately the same time, SL may not invoke your code for each one separately.  Instead, it may combine two or more of the touches into one event.  In case your script really needs to respond separately to each touch, SL will tell you how many touches an execution of the touch_start event handler represents.  That's the purpose of the phrase "integer num_detected" between the parentheses following touch_start.  But before fully explaining how that works, we need to learn some other things, so we won't elaborate on that yet.
If a user clicks on your object many times, the touch_start event handler code will generally get executed many times, once for each click.  But if multiple users click on your object at approximately the same time, SL may not invoke your code for each one separately.  Instead, it may combine two or more of the touches into one event.  In case your script really needs to respond separately to each touch, SL will tell you how many touches an execution of the touch_start event handler represents.  That's the purpose of the phrase "integer num_detected" between the parentheses following touch_start.  But before fully explaining how that works, we need to learn some other things, so we won't elaborate on that yet.


Rightnow, let's look at the process for actually [[LSL 101\Creating a Script|creating a script]] in SL.
Right now, let's look at the process for actually [[LSL 101\Creating a Script|creating a script]] in SL.

Revision as of 17:17, 20 June 2009

← Strings and Simple Output ↑̲  LSL 101  ̲↑ Creating a Script →

Here's our sample program, with a second event handler added. The touch_start event occurs whenever any avatar clicks on the object containing the script. Note again that the name of the event must be spelled touch_start, with the underscore. (The underscore doesn't show up in the title of this page just because the Wiki software displays underscores in titles as spaces.)

<lsl> default {

    state_entry()
    {
         // Let the object's owner know the script is working
         llOwnerSay( "Congratulations! Your script has started to execute." );
    }
    touch_start( integer num_detected )
    {
         // Let the object's owner know the script is working
         llOwnerSay( "I've been touched!" );
    }

} </lsl>

The start part of the event name refers to the fact that this event is generated whenever a user presses the left mouse button while the cursor is over the object. If for some reason you wanted your code to execute when the user lifted the button instead of pressing it, that event is named touch_end.

If a user clicks on your object many times, the touch_start event handler code will generally get executed many times, once for each click. But if multiple users click on your object at approximately the same time, SL may not invoke your code for each one separately. Instead, it may combine two or more of the touches into one event. In case your script really needs to respond separately to each touch, SL will tell you how many touches an execution of the touch_start event handler represents. That's the purpose of the phrase "integer num_detected" between the parentheses following touch_start. But before fully explaining how that works, we need to learn some other things, so we won't elaborate on that yet.

Right now, let's look at the process for actually creating a script in SL.