You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm quite new to lua and TTS scripting and first would like to thank you for your work which is a great source of inspiration :)
Looking at your code raised some questions, I hope it is OK to ask here
What I understand from AddHandler code :
it sets a global function named after the event
it took into consideration that such global function could already exists
new global function will call potential existing one + each registered handler
My question is about the return value : it looks like it returns the last handler return value... is it intended behaviour and why the last ?
I would have expected to be the "and" of all the returned values
_G[event] = function(...)
local globalHandler = EventManager.globalHandlers[event]
local returnValue
if globalHandler then
returnValue = globalHandler(...)
end
for _, handler in ipairs(EventManager.handlers[event]) do
returnValue = handler(...) and returnValue
end
return returnValue
end
So, if I add many tryObjectEnterContainer handlers, the return value will be true if all handlers succeded and false if at least one failed
Also, why FireEvent doesn't return any value ?
wouldn't it be ok to just call _G[event](...) ?
The text was updated successfully, but these errors were encountered:
vvedge
changed the title
[Question] EventManager - event return value ?
[Question] EventManager - about event return value
Jun 3, 2022
I'm quite new to lua and TTS scripting and first would like to thank you for your work which is a great source of inspiration :)
Looking at your code raised some questions, I hope it is OK to ask here
What I understand from AddHandler code :
it sets a global function named after the event
it took into consideration that such global function could already exists
new global function will call potential existing one + each registered handler
My question is about the return value : it looks like it returns the last handler return value... is it intended behaviour and why the last ?
I would have expected to be the "and" of all the returned values
So, if I add many tryObjectEnterContainer handlers, the return value will be true if all handlers succeded and false if at least one failed
Also, why FireEvent doesn't return any value ?
wouldn't it be ok to just call
_G[event](...)
?The text was updated successfully, but these errors were encountered: