Triggered while 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.

Syntax

touch( integer num_detected )

Event ID: 3.

Parameters

integer num_detected

Caveats

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

See also

Events

Functions