Jump to content

Recommended Posts

The easier way to handle this is to have an always-on handler that checks some internal variable to see if it does anything, such as in your case having a level check that is >= 10 and < 20.

 

The harder way from what you are doing but should be possible from the code here by removing the handler...

 

From scripts/input.lua:112-114:

function Input:AddKeyUpHandler( key, fn )
    return self.onkeyup:AddEventHandler(key, fn)
end

From scripts/events.lua:17-36:

function EventProcessor:AddEventHandler(event, fn)
    local handler = EventHandler(event, fn, self)
    
    if self.events[event] == nil then
        self.events[event] = {}
    end
    
    self.events[event][handler] = true
    
    return handler
end

function EventProcessor:RemoveHandler(handler)
    if handler then
        local ev = self.events[handler.event]
        if ev then
            ev[handler] = nil
        end
    end
end

TheInput:AddKeyUpHandler(KEY_R, function())

This should return the EventHandler created in AddEventHandler.

 

So you'd store this handle in your mod's global space.

SomeVar = TheInput:AddKeyUpHandler(KEY_R, function())

Then kill it later with:

TheInput.onkeyup:RemoveHandler(SomeVar)

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
×
  • Create New...