britzl / defold-input

Simplify input related operations such as gesture detection, input mapping and clicking/dragging game objects
MIT License
111 stars 26 forks source link

Can't unregister a button if supplied id is a string #4

Closed Jerakin closed 5 years ago

Jerakin commented 5 years ago
local button = require "in.button"

function init(self)
  button.register("button", function() print("Press") end)
end

function final(self)
  button.unregister("button")
end

function on_input(self, action_id, action)
  button.on_input(action_id, action)
end

This gives me an error, and by debugging it you can see even though it should set the node to nil the lookup doesn't work.

ERROR:SCRIPT: /utils/button.lua:81: Node used in the wrong scene
stack traceback:
    [C]: in function 'is_enabled'
    /utils/button.lua:81: in function 'is_enabled'
    /utils/button.lua:101: in function 'on_input'

However

local button = require "in.button"

function init(self)
  self.button = gui.get_node("button")
  button.register(self.button, function() print("Press") end)
end

function final(self)
  button.unregister(self.button)
end

function on_input(self, action_id, action)
  button.on_input(action_id, action)
end

Gives no error

britzl commented 5 years ago

Thanks! Fixed in https://github.com/britzl/defold-input/releases/tag/1.5.0