Sorry if the title is not very clear, in short I wanted to write myself a little script very quickly to simplify my life with GUIs, here is the script in question:
local Button = {
pressed = false
}
Button.__index = Button
function Button:on_input(action, ...)
if action.pressed and gui.pick_node(self.node, action.x, action.y) then
gui.play_flipbook(self.node, self.btn_pressed)
self.pressed = true
elseif self.pressed then
if action.released then
self.pressed = false
if gui.pick_node(self.node, action.x, action.y) then
self.func_action(...)
end
else
if not gui.pick_node(self.node, action.x, action.y) then
gui.play_flipbook(self.node, self.btn_normal)
else
gui.play_flipbook(self.node, self.btn_pressed)
end
end
end
end
return function (btn_node, btn_normal, btn_pressed, func_action)
return setmetatable({
node = btn_node,
btn_normal = btn_normal,
btn_pressed = btn_pressed,
func_action = func_action
}, Button)
end
But when I wanted to use it there is a small detail that I had forgotten, it is that the gui
function table can only be called from a gui_script
so did you another trick to avoid having to rewrite the same code in each script?
I tried passing gui
as a parameter of Button:on_input
in my code snippet but obviously it didn’t work (I didn’t feel smart for long ^^)
And happy new year to all by the way