distinguish between mouse click on viewport and mouse click on button start ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By franco73

In a catch game , i want to catch a moving sprite with mouse click.

I have an action “click” that i use for handling mouse input and execute a check function.

func _input(event): if event.is_action_pressed("click"): checkCatch()

I also added a code for starting the game whith a start button

func _on_BtStart_pressed():
	$BtStart.hide()
	emit_signal("start_game")

But when I click on button Start , my checkCatch() function is executed.

How can I prevent this this from happening?

:bust_in_silhouette: Reply From: i_love_godot

Is the button a Control? I’m new to Godot, but would the unhandled event help?

 _unhandled_input(event)
:bust_in_silhouette: Reply From: p7f

Hi,
you can put checkCatch() function inside _unhandled_input(event): instead of in _input(event). That way only will arrive to the game the inputs that are not handled by gui.

Thank you for your answers.

_unhandled_input(event) works fine for my issue.

I could also use a boolean variable 'gameStarted ’ with my action_pressed event that would prevent checkCatch() to be executed as long as the game is not started.

func _input(event): 
   if event.is_action_pressed("click")  and gameStarted: 
       checkCatch()

franco73 | 2019-01-08 23:11

Yes, you could also do that! I think that is better idea to use _unhandled_input always that you mix gui and gameplay and ui in the same scenes, as this would let you have as many controls you want without any change to code. Maybe now there is only one button and adding just one variable is not an issue, but perhaps later one you want to add other controls that sould also work when game already started without triggering gameplay effects. I dont know if im exolaining myself.

p7f | 2019-01-08 23:22

ok this sounds more efficient. I’ll stick to _unhandled_input.
Thanks again.

franco73 | 2019-01-09 10:17

You are welcome! If the answer solved your issue, then you may select it so others can see it’s solved

p7f | 2019-01-09 10:27