Touch

From Second Life Wiki
Revision as of 00:03, 30 April 2026 by Wulfie Reanimator (talk | contribs) (Added new example, moving another to touch_start instead...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.
  • Rigged mesh attachments do not support touch events, this is because you can steer your avatar/camera by click dragging your avatar body which is what the rigged mesh replaces. The only way to get a touch event on a rigged mesh attachment is via the right click context menu and clicking the "Touch" button.


Examples

You can use index 0 through (num_detected-1) with the various llDetected... functions to handle simultaneous touches at once.

For example, the following script shows the names of everyone touching it (click and hold) as floating text.

list touchers;

default
{
    // Collect names of avatars touching the object.
    touch(integer num_detected)
    {
        integer i;
        for (i = 0; i < num_detected; ++i)
        {
            string name = llDetectedName(i);
            if (llListFindList(touchers, [name]) == -1)
            {
                touchers += name;
            }
        }
        llSetText("I am being touched by " + llList2CSV(touchers) + ".", <1,1,1>, 1);
    }

    // Remove names of avatars as they let go.
    touch_end(integer num_detected)
    {
        integer i;
        for (i = 0; i < num_detected; ++i)
        {
            string name = llDetectedName(i);
            integer index = llListFindList(touchers, [name]);
            touchers = llDeleteSubList(touchers, index, index);
        }
        if (llGetListLength(touchers) > 0)
        {
            llSetText("I am being touched by " + llList2CSV(touchers) + ".", <1,1,1>, 1);
        }
        else
        {
            llSetText("", <1,1,1>, 1);
        }
    }
}

For most purposes, it's usually enough to handle just with the first toucher e.g. llDetectedKey(0).

default
{
    touch(integer num_detected)
    {
        llOwnerSay("I am being touched by " + llDetectedName(0) + ".");
    }
}

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