Difference between revisions of "Touch end"

From Second Life Wiki
Jump to: navigation, search
(More sensible use of Time functions in 1st example. Clarify num_detected in practice.)
(Remove reference to inaccurate misleading Jira issue. Clarify state change advice.)
Line 1: Line 1:
{{Template:Issues/SVC-3017}}{{LSL_Event|event_id=4|event_delay|event=touch_end
+
{{LSL_Event|event_id=4|event_delay|event=touch_end
 
|p1_type=integer|p1_name=num_detected|p1_desc
 
|p1_type=integer|p1_name=num_detected|p1_desc
 
|event_desc=Triggered when agent stops clicking on task
 
|event_desc=Triggered when agent stops clicking on task
Line 17: Line 17:
 
     {
 
     {
 
         llInstantMessage( llDetectedKey(0), "You held the mouse button down for " + (string) llGetTime() + " seconds");
 
         llInstantMessage( llDetectedKey(0), "You held the mouse button down for " + (string) llGetTime() + " seconds");
    }
 
}</lsl><lsl>// If using a touch to change states be careful about the touch_ event order...
 
 
// On clicking a prim with touch events we trigger touch_start (as), touch (during) and touch_end (as released).
 
 
// The chain of events is established in the script as touch_start is triggered that remains intact until either
 
 
// touch_end is triggered or a new touch_start (discounting resets, deletions, taking to inventory etc.).
 
 
default
 
{
 
    touch_start(integer nd)
 
    {
 
        llSay(0, "You just started touching me so I'm going to the other state...");
 
        state other;
 
    }
 
// A very rapid click would (and does if your VERY quick) beat the state change so the script would/does not behave as expected.
 
}
 
state other
 
{
 
    touch_end(integer nd)
 
    {
 
// The average click will have you catapult through this state with nothing but a chatted message to remember it by.
 
        llSay(0, "The touch that brought you here just ended so I'm going back to default...");
 
        state default;
 
 
     }
 
     }
 
}</lsl>
 
}</lsl>
 +
 +
|notes=*If using a touch to change states be careful about the touch_ event order. '''The best advice is NOT to do state changes from within touch_start.''' Use touch_end and do the state change there. Changing state from within touch_start can cause the next occurrence of THAT touch_start code to be missed. 
 +
 +
*On clicking a prim with touch events we trigger touch_start (on first contact), touch (during) and touch_end (as released).
 +
 
|helpers
 
|helpers
 
|also_header
 
|also_header

Revision as of 04:24, 27 December 2012

Description

Event: touch_end( integer num_detected ){ ; }

Triggered when agent stops clicking on task

• 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.
All Issues ~ Search JIRA for related Bugs

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_start(integer num_detected)
   {
       llResetTime();
   }
   touch_end(integer num_detected)
   {
       llInstantMessage( llDetectedKey(0), "You held the mouse button down for " + (string) llGetTime() + " seconds");
   }

}</lsl>

Notes

  • If using a touch to change states be careful about the touch_ event order. The best advice is NOT to do state changes from within touch_start. Use touch_end and do the state change there. Changing state from within touch_start can cause the next occurrence of THAT touch_start code to be missed.
  • 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

Functions

•  llPassTouches

Deep Notes

Signature

event void touch_end( integer num_detected );