We are trying to get buttons to work, but are having problems.
In: /gui-script/TitleGUI.gui_script the following never fires:
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed and self.active then
local node = gui.get_node("ButtonOptions")
if gui.pick_node(node, action.x, action.y) then
NextScreen = 3
ScreenFadeStatus = 1
print("Pressed")
end
end
end
function on_input(self, action_id, action)
-- <--------- This point!
if action_id == hash("touch") and action.pressed and self.active then
local node = gui.get_node("ButtonOptions")
if gui.pick_node(node, action.x, action.y) then
NextScreen = 3
ScreenFadeStatus = 1
print("Pressed")
end
end
end
And just a friendly tip;
People are (sadly) very unlikely to download the source and do the debugging for you. It can be quite cumbersome for a bystander to invest their time to understand someone else project and logic.
Instead try to describe any errors you encounter and what the expected behaviour is. Try to explain what you tried, and how you yourself debugged the code, to help people to get a quick overview of the problem and be able to exclude ideas you already tried.
For example, in the snippet above, you could have written that you;
looked through the console output and verified that there in fact aren’t any runtime errors.
added a print statement to the on_input function, verified that it was actually called (meaning that the GO/script actually has input focus).
split the if-statement into multiple checks, verifying that each of the control statements (action_id == hash("touch"), action.pressed and self.active) were evaluating to true.
cross check the hash("touch") action id with what was written in the .input_binding file, verifying that there was a trigger with the correct name.
Sometimes it isn’t easy to figure out these steps of course, but try to break up the code into parts that could fail to get some insight on possible leads.
This case is also a prime example where the built-in Lua debugger comes in handy. For example you could set a breakpoint at the first if-statement in the function, go to Debug->Run with Debugger, perform the action in game and wait for the editor pause at the breakpoint. Once the execution is paused, you could inspect the variables/values. More information on using the debugger can be found here: https://www.defold.com/manuals/debugging/