I want to prevent the input from being spammed, with a 3 second wait time after each click

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jared111
fired = Input.is_action_just_pressed("Mouse_right")
if fired == true:
	emit_signal("fired")
:bust_in_silhouette: Reply From: njamster

Use a boolean variable and a Timer:

var can_fire = true

func _process(_delta):
    if can_fire and Input.is_action_just_pressed("Mouse_right"):
        can_fire = false
        $Timer.start()
        emit_signal("fired")

func _on_Timer_timeout():
    can_fire = true

Thank you!! i was trying to experiment with timer before but i could never get it to print the countdown in the debugger no idea why.

Jared111 | 2020-05-31 23:55

but i could never get it to print the countdown in the debugger

Should be as easy as:

func _process(_delta):
    if not $Timer.is_stopped():
        print($Timer.time_left)

Furthermore I realized that you don’t actually need the variable:

func _ready():
    $Timer.one_shot = true # you can do this in the inspector as well

func _process(_delta):
    if Input.is_action_just_pressed("Mouse_right") and $Timer.is_stopped():
        $Timer.start()
        emit_signal("fired")

njamster | 2020-06-01 10:17