Countdown with 1 second interval

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

Friends I want to have a label. Let it be 3 seconds that it shows: 3,2,1 and let it be with an interval of 1 second. Sorry if a silly question I couldn’t find something like that on Google. How could I do it? Tried with set_wait_time (1) but it doesn’t work for me

:bust_in_silhouette: Reply From: Ertain

How about setting a Timer for 3 seconds, and then checking whether the time remaining is under a certain number?

func _process( _change: float ):
    if countdown_timer.time_left < 1.0:
        countdown_label.text = 1
    elif countdown_timer.time_left < 2.0:
        countdown_label.text = 2
     # This is the last check since the loop would always evaluate to "true" on values below 3.0.
    elif countdown_timer.time_left < 3.0:
        countdown_label.text = 3

Also, be sure to set the Timer to one-shot.

Thanks for the reply. It would be possible for you to pass the project on to me. Please, I would like to analyze the code.`enter image description here

extends Control

func _ready():

if $Timer.time_left < 1.0:
	$Label.set_text("1")
	
elif $Timer.time_left < 2.0:
	$Label.set_text("2")
	
elif $Timer.time_left < 3.0:
	$Label.set_text("3")
	
pass

RetroDan007 | 2021-12-27 21:45

It would be possible for you to pass the project on to me. Please, I would like to analyze the code.

I’m sorry, I can’t create a complete project for you; that’s something you have to do by yourself.

Ertain | 2021-12-27 21:59

:bust_in_silhouette: Reply From: deaton64

Hi,

Or you could keep it simple:

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	$Timer.wait_time = 4
	$Timer.start()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	$Label.text = str(int($Timer.time_left))