Hi all, thank you all for helping me ask around regarding the question I had over at https://godotforums.org/d/36639-wanting-to-add-timer-to-confirm-selection-of-object-rock-paper-scissors which wasn't ideal of what I was asking as I was asking a fair bit there. Learning still to segment down to nitty gritty.. After further looking around I managed to figure out how to add a timer! That's a start..

Anyways my next question is:

I have added code so that when the up or down buttons are pressed the timer starts so that a selection is made before the time runs out. However I can't seem to figure out how to ignore additional starts of the timer as I don't want that. All I want is for the up or down to initiate the timer from 10 seconds down and not reset when I press up or down again.

Snipets of the code related to my question I have so far:

Globals.gd (attached to the main stage scene):

@export var round_time = 10
var timer_node = null
var time_left

func _ready():
	time_left = round_time
	
func start_timer():
	timer_node = Timer.new()
	timer_node.name = "Round Timer"
	timer_node.wait_time = 1
	timer_node.timeout.connect(on_round_timer_timeout) 
	add_child(timer_node)
	timer_node.start()

func on_round_timer_timeout():
	time_left -= 1
	print(time_left)
	if time_left < 0:
		timer_node.stop()
		print("result")

Player.gd:

	if Input.is_action_just_pressed("up"):
		_scroll(1)
		gl.start_timer()
	elif Input.is_action_just_pressed("down"):
		_scroll(-1)
		gl.start_timer()```



Also how do I lock the input once the time runs out? 
  • Toxe replied to this.

    milktank81 Timer has a time_left property. Each key press you could check if time_left is > 0.0 which means that the timer is running and if it is then just ignore the key press.

    Or you could manually set a flag (something like timer_is_running) when you start the timer and check if it is running. Set the flag to false once the timer stops.

      Toxe Thank you for the response, I think that's the part I'm stuck with, as I'd like to manually set a flag, as I'd like to be able to keep pressing up or down and let the timer run out, and once time is up, input is locked.

      • Toxe replied to this.

        milktank81 In your player script do something like this:

        if Input.is_action_just_pressed("up"):
        	if gl.is_timer_stopped():
        		_scroll(1)
        		gl.start_timer()
        elif Input.is_action_just_pressed("down"):
        	if gl.is_timer_stopped():
        		_scroll(-1)
        		gl.start_timer()

        And then add a is_timer_stopped() function to your other script that returns either true or false, depending on the state of the timer.