Difference between revisions of "Touch"

From Second Life Wiki
Jump to navigation Jump to search
(Touch moved to LSL Touch)
 
 
(22 intermediate revisions by 10 users not shown)
Line 1: Line 1:
#REDIRECT [[LSL Touch]]
{{LSL_Event|event_id=3|event_delay|event=touch
|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).
Triggered on touch start, each minimum event delay while held, and touch end.
|constants
|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.
|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.
<source lang="lsl2">default
{
    touch(integer num_detected)
    {
          llOwnerSay("I am being touched by " + llDetectedName(0) + ".");
    }
}</source>
 
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.
 
<source lang="lsl2">
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
    // ...
}
    }
}
</source>
 
Clicking and holding can't be used to call a menu since the menu will pop out continuosly.
Use a flag to avoid this.
 
<source lang="lsl2">
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
            }                 
    }   
}
</source>
 
|helpers
|also_header
|also_events=
{{LSL DefineRow||[[touch_start]]|}}
{{LSL DefineRow||[[touch_end]]|}}
|also_functions=
{{LSL DefineRow||[[llSetTouchText]]|Set the pie menu's text for touch-action}}
{{LSL DefineRow||[[llPassTouches]]|Allows clicks captured by a child prim to be passed to the root as well}}
|also_articles
|also_footer
|notes
|mode
|deprecated
|cat1=Touch
|cat2=Detected
|cat3=Grab
|cat4=Passable
}}

Latest revision as of 14:30, 20 May 2016

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