Skip to content
lsl.devlsl.devLSL Dev

touch

event
Event syntax
touch(
  1. integer num_detected// Total number of touching agents detected (usable with llDetected* functions).
) { … }

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.

How to use
touch(integer num_detected)
{
}
  • 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.
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.
19 collapsed lines
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) + ".");
}
}
  • 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
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from Touch, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

  • Touch (revision 1218821, )

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.