Difference between revisions of "LSL 101/The touch start Event"
m (repair broken link) |
m (editing... see discussion) |
||
Line 1: | Line 1: | ||
[[Category:LSL 101]] | [[Category:LSL 101]] | ||
{{NavNextPrev|prev= | {{NavNextPrev|prev=Event Handler Parameters|next=Variables}} | ||
{{LSL Wikibook Index}} | |||
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.) | 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.) | ||
Line 25: | Line 26: | ||
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. | ||
'''Please continue this tutorial with [[LSL_101/Variables |Variables]], or return to the [[LSL_101/Event Handler Parameters |Events]] page.''' |
Revision as of 17:06, 7 July 2012
← Event Handler Parameters | ↑̲ LSL 101 ̲↑ | Variables → |
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.
Please continue this tutorial with Variables, or return to the Events page.