Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] EventManager - about event return value #12

Open
vvedge opened this issue Jun 3, 2022 · 0 comments
Open

[Question] EventManager - about event return value #12

vvedge opened this issue Jun 3, 2022 · 0 comments

Comments

@vvedge
Copy link

vvedge commented 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

_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](...) ?

@vvedge vvedge changed the title [Question] EventManager - event return value ? [Question] EventManager - about event return value Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant