Jump to content

Why can't custom events be cancelled?


vicisdev

Recommended Posts

I was expecting this to work, but custom events seem not cancellable. Is this how custom events should work?

local number = 0

addEvent("customEvent")

addEventHandler("onPlayerJoin", root, function()
    local player = source

    bindKey(player, "e", "down", function()
        number = number + 1
        triggerEvent("customEvent", player)
    end)
end)

addEventHandler("customEvent", root, function()
    outputDebugString(number)
    if number % 2 == 0 then cancelEvent() end
end)

addEventHandler("customEvent", root, function()
    if wasEventCancelled() then
        outputDebugString("Cancelled")
    else
        outputDebugString("Called")
    end
end, true, "low")

To provide a little bit of context I was trying to implement a way for developers to cancel my custom events default behaviors using cancelEvent.

 

Edited by vicisdev
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...