Difference between revisions of "Touch"

From Second Life Wiki
Jump to navigation Jump to search
(Added 2nd example)
(Remove reference to inaccurate Jira issue. Clarify touch event sequence)
Line 1: Line 1:
{{Template:Issues/SVC-3017}}{{LSL_Event|event_id=3|event_delay|event=touch
{{LSL_Event|event_id=3|event_delay|event=touch
|p1_type=integer|p1_name=num_detected|p1_desc
|p1_type=integer|p1_name=num_detected|p1_desc
|event_desc=Triggered whilst an agent is clicking the task. It will continue to be triggered until the the prim/object is stopped being clicked (it triggers multiple times).
|event_desc=Triggered whilst an agent is clicking the task. It will continue to be triggered until the the prim/object is stopped being clicked (it triggers multiple times).
Line 5: Line 5:
|spec
|spec
|caveats=* If a prim [[face]] has [[Navigating Shared Media|Shared Media]] enabled and the avatar's viewer supports this feature, LSL scripts will not detect touches on that face. Touches from older clients will be detected.
|caveats=* If a prim [[face]] has [[Navigating Shared Media|Shared Media]] enabled and the avatar's viewer supports this feature, LSL scripts will not detect touches on that face. Touches from older clients will be detected.
|examples=<lsl>default
|notes=*On clicking a prim with touch events we trigger touch_start (on first contact), touch (during) and touch_end (as released).
 
|examples=You can use numbers 0 through (num_detected-1) with the various llDetected... functions to get detected agent keys etc. For most purposes, it is adequate to bother only with the first detected toucher e.g. llDetectedKey(0). It is rare (but not impossible) for num_detected to be other than 1.
<lsl>default
{
{
     touch(integer num_detected)
     touch(integer num_detected)

Revision as of 03:31, 27 December 2012

Description

Event: touch( integer num_detected ){ ; }

Triggered whilst an agent is clicking the task. It will continue to be triggered until the the prim/object is stopped being clicked (it triggers multiple times).

• integer num_detected

Caveats

  • If a prim face has Shared Media enabled and the avatar's viewer supports this feature, LSL scripts will not detect touches on that face. Touches from older clients will be detected.


Examples

You can use numbers 0 through (num_detected-1) with the various llDetected... functions to get detected agent keys etc. For most purposes, it is adequate to bother only with the first detected toucher e.g. llDetectedKey(0). It is rare (but not impossible) for num_detected to be other than 1. <lsl>default {

    touch(integer num_detected)
    {
         llOwnerSay("I am being touched by " + llDetectedName(0) + ".");
    }

}</lsl>

This next example demonstrates detecting when the owner of the object clicks-and-holds on the object for 1 second in order perhaps to access a management menu or similar, Normal brief clicks are distinguished.

<lsl> default {

   touch_start(integer num_detected)
   {

llResetTime();

   }
   touch(integer num_detected)
   {

if (llDetectedKey(0) == llGetOwner() && llGetTime() > 1.0) { // The owner has touched this object for longer than 1 second // execute some special feature such as issuing a management dialog // ... }

   }
   touch_end(integer num_detected)
   {

if (llGetTime() < 1.0) { // The user did a normal quick click on the object // execute actions for normal clicks // ... }

   }

} </lsl>

Notes

  • On clicking a prim with touch events we trigger touch_start (on first contact), touch (during) and touch_end (as released).

See Also

Events

•  touch_start
•  touch_end

Functions

•  llSetTouchText Set the pie menu's text for touch-action
•  llPassTouches Allows clicks captured by a child prim to be passed to the root as well

Deep Notes

Signature

event void touch( integer num_detected );