Difference between revisions of "Touch start"

From Second Life Wiki
Jump to navigation Jump to search
(Remove obsolete warning. Correct and clarify state change advice)
m (Replaced old <LSL> block with <source lang="lsl2">)
Line 8: Line 8:
|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) 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.
|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>
<source lang="lsl2">
default
default
{  
{  
Line 19: Line 19:
     }
     }
}
}
</lsl>
</source>


|helpers
|helpers

Revision as of 00:03, 22 January 2015

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 clockcycle

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_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 event 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 events we trigger touch_start (on first contact), touch (during) and touch_end (as released).

Deep Notes

Signature

event void touch_start( integer num_detected );