Timer Node Best Practices

Hi,

I was using some timers in my project and was wondering about what the best practices are revolving around them. I found myself using them in two different ways, which I’ll post as little snippets here:

if Input.is_action_pressed("Shoot") && can_shoot:
	can_shoot = false
	$ShotTimer.start()
	#DoShootingStuff

func _on_timer_timeout():  #Catching the timer signal
	can_shoot = true

And the other way is

func hit():
	if $TimerOne.is_stopped():
		$TimerOne.start()  #0.5s timer
		$TimerTwo.start()  #0.1s timer
		#Do A Thing
	elif $TimerTwo.is_stopped():   #Thing 1 is on cooldown, do Thing 2?
		$TimerTwo.start()  #0.1s timer
		#Do A Different Thing
	else:         #Both Things are on cooldown, do nothing
		pass

Is using one of these strategies always better than the other or are there circumstances where it can be different?

and there’s tween too :slight_smile:

2 Likes

This reduces variables, if you need to interrupt the can_shoot you do not have to remember to stop the timer too. Make sure to name your timers aptly.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.