Touch
Looking for the current API? Open the touch reference →
Wiki description
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.
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) + ".");
}
}See also: functions
See also: events
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.