Object touchability not updated if touch event assigned outside global scope
tracked
Frionil Fang
Specifically: the object's touchable state will reflect only if touch_start has a function assigned in the global script scope. The function assignments appear to work as expected, it's only the viewer UI that is not properly updated to allow/disallow touches.
Unsure if this affects other types of events. Being able to disable or reassign an event handler at any time would be useful e.g. to make an object unclickable while it does some processing.
Repro script:
function func()
ll.OwnerSay("touched, remove touch")
touch_start = nil
end
function timer()
ll.OwnerSay("(re)enable touch_start")
touch_start = func
ll.SetTimerEvent(0)
end
touch_start = func --assign a function in global scope, object becomes touchable
ll.OwnerSay(`starting, touch_start type = {type(touch_start)}`)
ll.SetTimerEvent(5) -- timer restores touchability in 5 seconds
Touching removes the touch function, but the object still appears as touchable. Once restored by the timer, you can touch it again.
If you comment out the global-scope touch_start = func assignment, the object remains untouchable even after the timer assigns the function.
Log In
H
Harold Linden
So having the event handlers be global functions was 100% a hack to get things working at all, but now that things are slightly more fleshed out we're looking at how to address this.
Our current thinking is that we want a top-level object like
LLEvents
or something like that that can have functions assigned to it like so:function LLEvents.touch_start(num)
ll.OwnerSay("foobar")
end
-- or
local function touch_handler(num)
ll.OwnerSay("foo")
end
LLEvents.touch_start = touch_handler
-- some time later, when you don't care about that event anymore
LLEvents.touch_start = nil
Eventually, we also want to allow something like accessing
LLEvents.touch_start
to get an object allowing you to dynamically add / remove handlers, as well as give scripters some functions for synchronously flushing the event queue if they want to ignore queued events of a particular type.We'll get to this after the unfortunate
integer
situation is cleared up.Signal Linden
tracked
This is expected for now, your event handlers are whatever is present when the main function finishes executing, and it doesn't scan for event handler changes beyond that.
We're planning to change how event handlers are registered to make them easier to hook / unhook event listeners, as well as utilities to clear pending events, like people previously used state switching to do.
We'll update everyone when there's progress on that front!
WolfGang Senizen
A slightly simpler repro
timer = function()
touch_start = ll.OwnerSay
ll.SetTimerEvent(0.0)
end
ll.SetTimerEvent(0.01)
touching should ownersay but it doesn't