Difference between revisions of "Touch start"

From Second Life Wiki
Jump to: navigation, search
m
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Issues/SVC-3017}}{{LSL_Event|event_id=2|event_delay|event=touch_start
+
{{LSL_Event|event_id=2|event_delay|event=touch_start
 
|p1_type=integer
 
|p1_type=integer
 
|p1_name=num_detected
 
|p1_name=num_detected
|p1_desc=Number of agents detected touching during the last clockcycle
+
|p1_desc=Number of agents detected touching during the last clock cycle
 
|event_desc=Triggered by the start of agent clicking on task
 
|event_desc=Triggered by the start of agent clicking on task
 
|constants
 
|constants
 
|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=You can use numbers 0 through num_detected - 1 to get detected agent keys:
+
* The default behavior is: If you have a multi-prim object and the root has a [[touch_start]] handler AND one or more child prims has a [[touch_start]] handler, the root prim's handler will be called when it (the root) or a child without a handler is touched. If you touch a child prim that has a [[touch_start]] handler, it will receive the event and the root prim will not.
<lsl>default
+
** This behavior can be configured with [[llPassTouches]]. After configuring a prim's touch-passing behavior you can delete the script that configured the prim.
 +
|examples=You can use numbers 0 through (<code>num_detected</code>-1) with the various <code>llDetected</code>... 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 <code>num_detected</code> to be other than 1.
 +
<source lang="lsl2">
 +
default
 
{  
 
{  
 
     touch_start(integer num_detected)
 
     touch_start(integer num_detected)
 
     {
 
     {
         integer i = 0;
+
         key    avatarKey  = llDetectedKey(0);
         for(; i<num_detected; ++i)
+
         string avatarName = llDetectedName(0);
            llWhisper(0, "Touched by " + llKey2Name(llDetectedKey(i)));
+
    }
+
}</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).
+
         llInstantMessage(avatarKey, "Hello " + avatarName );
 
+
// 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
+
</source>
{
+
 
    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>
+
 
|helpers
 
|helpers
 
|also_header
 
|also_header
Line 50: Line 31:
 
{{LSL DefineRow||[[llSetTouchText]]|}}
 
{{LSL DefineRow||[[llSetTouchText]]|}}
 
{{LSL DefineRow||[[llPassTouches]]|}}
 
{{LSL DefineRow||[[llPassTouches]]|}}
{{LSL DefineRow||[[LlDetectedTouchFace]]|}}
+
{{LSL DefineRow||[[llDetectedTouchFace]]|}}
{{LSL DefineRow||[[LlDetectedTouchST]]|}}
+
{{LSL DefineRow||[[llDetectedTouchST]]|}}
{{LSL DefineRow||[[LlDetectedTouchUV]]|}}
+
{{LSL DefineRow||[[llDetectedTouchUV]]|}}
{{LSL DefineRow||[[LlDetectedTouchPos]]|}}
+
{{LSL DefineRow||[[llDetectedTouchPos]]|}}
{{LSL DefineRow||[[LlDetectedTouchNormal]]|}}
+
{{LSL DefineRow||[[llDetectedTouchNormal]]|}}
{{LSL DefineRow||[[LlDetectedTouchBinormal]]|}}
+
{{LSL DefineRow||[[llDetectedTouchBinormal]]|}}
 
|also_articles
 
|also_articles
 
|also_footer
 
|also_footer
|notes
+
|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.''' Add a [[touch_end]] handler and do the state change there. Changing state from within [[touch_start]] can cause the next occurrence of THIS [[touch_start]] code to be missed. 
 +
 
 +
*On clicking a prim with touch event handlers, the following handlers are triggered: [[touch_start]] (on first contact), [[touch]] (during) and [[touch_end]] (as released).
 
|mode
 
|mode
 
|deprecated
 
|deprecated
Line 64: Line 47:
 
|cat2=Detected
 
|cat2=Detected
 
|cat3=Grab
 
|cat3=Grab
|cat4
+
|cat4=Passable
 
}}
 
}}

Latest revision as of 22:46, 1 January 2016

Description

Event: touch_start( integer num_detected ){ ; }

Triggered by the start of agent clicking on task

• integer num_detected Number of agents detected touching during the last clock cycle

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.
  • The default behavior is: If you have a multi-prim object and the root has a touch_start handler AND one or more child prims has a touch_start handler, the root prim's handler will be called when it (the root) or a child without a handler is touched. If you touch a child prim that has a touch_start handler, it will receive the event and the root prim will not.
    • This behavior can be configured with llPassTouches. After configuring a prim's touch-passing behavior you can delete the script that configured the prim.
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.

default
{ 
    touch_start(integer num_detected)
    {
        key    avatarKey  = llDetectedKey(0);
        string avatarName = llDetectedName(0);
 
        llInstantMessage(avatarKey, "Hello " + avatarName );
    }
}

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. Add a touch_end handler and do the state change there. Changing state from within touch_start can cause the next occurrence of THIS touch_start code to be missed.
  • On clicking a prim with touch event handlers, the following handlers are triggered: touch_start (on first contact), touch (during) and touch_end (as released).

Deep Notes

Signature

event void touch_start( integer num_detected );