Topic was automatically imported from the old Question2Answer platform.
Asked By
NewbieGodotUser
I want to know how to make a variable (let’s call it count for now) which equals a number (lets say 10) to have 1 subtracted from it every second. So after one second count = 9, then count = 8, then count = 7, etc.
Most easily you can use the Timer node, how to use it like this on Godot 4
var count := 10
func _ready():
var timer: Timer = Timer.new()
add_child(timer)
var subtract = func():
count -= 1
# if the count value reaches 0
# then the value will be made 10 agains
if count == 0:
count = 10
print(count)
timer.start()
timer.connect("timeout", subtract)
This looks very nice.
Wakatta | 2022-09-14 23:00
Thank you for your help! It is very much appreciated!