![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | SloshySpace |
I’ve been developing a game that needs a score that updates every second. I fairly new and have seen the timer node which counts down.
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | SloshySpace |
I’ve been developing a game that needs a score that updates every second. I fairly new and have seen the timer node which counts down.
![]() |
Reply From: | jgodfrey |
There are a number of ways to do this. Here’s the basics with a Timer
.
Timer
to a sample scenewait_time = 1
, autostart = true
, and one_shot = false
timeout
signal to a script containing something like:.
var score = 0
func _on_Timer_timeout() -> void:
score += 1
print(score)
So, each time the timer “times out” (after 1 second here), it’ll call the _on_Timer_timeout()
function, which will increment the score. Once that happens, the Timer
will automaticlally reset to 1 second and being counting down again, repeating the process.
As another option (not using a Timer
) you could just manage this by hand, via the _process()
function. Something like:
var time_out = 1
var time = time_out
func _process(delta: float) -> void:
if time > 0:
time -= delta
else:
time = time_out
score += 1
print(score)
jgodfrey | 2023-01-27 03:50
I was having trouble with making it print the new score, but all you need todo is change print(score)
to text = str(score)
SloshySpace | 2023-01-29 03:59