Touch

From Second Life Wiki
Jump to navigation Jump to search

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). Triggered on touch start, each minimum event delay while held, and touch end.

• 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.

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

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.

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
	    // ...
	}
    }
}

Clicking and holding can't be used to call a menu since the menu will pop out continuosly. Use a flag to avoid this.

integer touched;  

default
{

    touch_start(integer n)
    {
        touched = FALSE;//HERE, before llResetTime() otherwise it doesn't run        
        llResetTime();
    }    
            
    touch(integer n)
    {
        if (llGetTime() > 1.0 && touched == FALSE)
            {     
                //Call here the menu
                touched = TRUE;                
            }        
    }
    
    touch_end(integer n)
    {
        if (llGetTime() <= 1.0)
            {        
	        //Do something
            }                  
    }    
}

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 );