Fix touch_start behaviour in slua
WolfGang Senizen
LSL has an awkward
bug
/behavior
with touch_start
If a user is already touching a prim, no other users
touch_start
s will trigger, only their touch
and touch_end
events.This is awkward and seemingly undocumented at least on the wiki.
While it may not be something that can be changed in lsl, it would be nice to clear this up in slua and not carry this "bug" over
LSL script
list ks = [];
handle(string name, integer t) {
while(t--) {
string evnt = name + ": " + llDetectedName(t);
if(llListFindList(ks,[evnt]) == -1) {
ks += evnt;
}
}
ks = llListSort(ks,1,1);
llSetLinkPrimitiveParamsFast(0, [PRIM_TEXT,llDumpList2String(ks,"\n"),<1,1,1>,1]);
llSetTimerEvent(5.0);
}
default {
state_entry() {
llSetLinkPrimitiveParamsFast(0, [PRIM_TEXT,"",<1,1,1>,1]);
}
touch_start(integer t) {
handle("touch_start",t);
}
touch(integer t) {
handle("touch",t);
}
touch_end(integer t) {
handle("touch_end",t);
}
timer() {
ks = [];
llSetTimerEvent(0.0);
llSetLinkPrimitiveParamsFast(0, [PRIM_TEXT,"",<1,1,1>,1]);
}
}
SLua script
local ks = {}
local clearHandle = nil
local function clear()
ll.SetLinkPrimitiveParamsFast(0, {PRIM_TEXT,"",vector.one,1})
ks = {}
end
local function handler(name)
return function(events:{DetectedEvent})
for _,event in events do
local evnt = `{name}: {event:getName()}`
if not table.find(ks, evnt) then
ks[#ks+1] = evnt
end
end
table.sort(ks)
ll.SetLinkPrimitiveParamsFast(0, {PRIM_TEXT,table.concat(ks,"\n"),vector.one,1})
if clearHandle then LLTimers:off(clearHandle) end
clearHandle = LLTimers:once(5, clear)
end
end
clear()
LLEvents:on("touch_start", handler("touch_start"))
LLEvents:on("touch", handler("touch"))
LLEvents:on("touch_end", handler("touch_end"))
Both of these scripts require 2 users to click, and you can see that only the person that clicks first gets a touch_start set text.
Log In
Nexii Malthus
This bug can be even more annoying in SLua where you may have to deal with event registrations more fluidly and precisely for multi-touch objects. Tracking touches of different users from start to end.