Referencing two buttons in the same function? (SOLVED)

I have a menu screen that includes a start button and another button that goes to another screen. My start button works fine but I’m not sure how to reference the action of the second button. My start button is controlled in on_input and I tried using an elseif statement to register the second button but it doesn’t give any input. I ran a print on the script so it runs fine but since I get no console error I’m not sure what the issue could be. Here is my on_input function. Is it possible to but my second button in here?

function on_input(self, action_id, action)
		if action_id == hash("click") and action.pressed and self.active then
			local start = gui.get_node("start")
			if gui.pick_node(start, action.x, action.y) then
				msg.post("#", "hide_start")
				msg.post("#level_select", "show_level_select")
			--[[elseif gui.pick_node(start, action.x, action.y) then
				msg.post("#", "hide_start")
				msg.post("#achievements", "show_achievements") --]]
			end
		end
	end 
1 Like

The conditions of the “if” and “elseif” are both the same, so only the first branch will be run (elseif is only checked if the statements above it return false).

You need to set another variable is the same way you set the “start” variable and assign it the second button:

function on_input(self, action_id, action)
		if action_id == hash("click") and action.pressed and self.active then
			local start = gui.get_node("start")
			local secondButton = gui.get_node("secondButton")
			if gui.pick_node(start, action.x, action.y) then
				msg.post("#", "hide_start")
				msg.post("#level_select", "show_level_select")
			elseif gui.pick_node(secondButton, action.x, action.y) then
				msg.post("#", "hide_start")
				msg.post("#achievements", "show_achievements")
			end
		end
	end 
3 Likes

Got it. Thanks!

1 Like