How to adjust this for multiple buttons? (SOLVED)

Hello, I’m trying to copy and paste the button, (and move it so it doesn’t overlap the original one) from this example here:

It’s not working so far … how do you edit the pointer_over.gui_script file to allow this to work for multiple buttons ?

The function gui.pick_node(node, x, y) lets you check if a 2d point is inside the bounds of a gui node. Let’s say that you have two GUI nodes, `button_a" and “button_b” then the basics of using gui.pick_node() is this:

function on_input(self, action_id, action)
	if gui.pick_node(gui.get_node("button_a"), action.x, action.y) then
		print("above button A")
	elseif gui.pick_node(gui.get_node("button_b"), action.x, action.y) then
		print("above button B")
	else
		print("outside")
	end
end

This will tell you if an input action is above button A, button B or outside both.

So the question is what kind of changes did to the script and what the id was of the new button you created?

Hmm I did a copy of the original ‘button’ which gave me an additional button ‘button1’ in the pointer_over.gui - I think I didn’t arrange the logic correctly like your example shows - let me check

Also I changed the Y coor of button1, so it wouldn’t be on top of ‘button’

Ok, make sure you understand the basic concepts here, and ask if you’re uncertain.

1 Like

Ok I was close, the main difference is I was trying with self. vs gui.get_node - this works !

function on_input(self, action_id, action)
  if action_id == nil then --<5>
    if gui.pick_node(gui.get_node("button"), action.x, action.y) then -- <6>
      print("over button")
    elseif gui.pick_node(gui.get_node("button1"), action.x, action.y) then
      print("over button1")
    else
      print("neither button")
    end
  end
end
1 Like

Thanks again - I’m impressed with how responsive the defold forums are :slight_smile: !

4 Likes