_on_Timer_timeout(): How to start an InputEventMouseButton?

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

So that a mouse click on my screen trigger an animation at the end of the timer?

:bust_in_silhouette: Reply From: gswashburn

1.) add a timer called “MouseTimer” to your game.
2.) set a wait time for “MouseTimer” (5 secs), override that in code
3.) set the “MouseTimer” to “one shot”
4.) connect the “MouseTimer” “timeout()” signal to your game script
5.) create an animation for Node (I assumed Player) called “MouseTimer”
6.) add code to play that animation in “timeout()” signal in game script

(See code below)

func _input(event):
	if InputEventMouseButton: # Triggers on any mouse button
		$MouseTimer.wait_time = 2 # Override wait time (in Secs)
		$MouseTimer.start() # Start Timer
func _on_MouseTimer_timeout():
	#print("MouseTimer Finished") # testing mouse timer
	$Player/AnimationPlayer.current_animation = "MouseTimer" # set current animation

If you want a use a specific mouse button, just add code after if InputEventMouseButton: Oh and I am assuming you are using Godot3

Hope this helps :slight_smile:

Thxs, but actually I want an animation or a label to be triggered by a mouse click when the timer is out. Not to start the timer eh?
Something like:

func _on_Timer_timeout():
if InputEventMouseButton: 
$Hmm/Label.start() or $("AnimationPlayer").play("exemple")

Here the trouble is, the event is unindentified, and I don’t know how set it in that timer func.
And yes, usin Godot 3. :slight_smile:

Syl | 2018-04-02 15:21

So are you,
1.) asking to trigger a mouse click when the timer times out? which in turn triggers an animation
2.) or are you saying that when a timer times out you want the user to trigger the animation on a mouse click, but only if the timer has expired?

Assuming its #2 Just set a flag in the Timer timeout signal and then add it as a “and” to your if statement somewhere else, like func _input(event).

extends Node

var timer_expired

func _ready():

func _on_Timer_timeout():
     timer_expired = true

func _input(event):
     if InputEventMouseButton and timer_expired:
          $Hmm/Label.start() or $("AnimationPlayer").play("example")

gswashburn | 2018-04-02 15:52

That’s it! Cheers for you!

Syl | 2018-04-02 16:21

Don’t forget to set timer_expired back to false after the triggered event :slight_smile:

gswashburn | 2018-04-02 16:55

Yep, done. Thxs again! :slight_smile:

Syl | 2018-04-02 17:07