My timer's timeout function is not displaying in sync with my frame rate I think?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

Hi all,

I have a timer and all it’s really doing is counting up from 0 to whatever my score is.
The idea is, when the level is finished. Your score counts up in a dramatic way to make the player feel good about their progress.

Currently though, if the score were say 12, the timer would count:
2, 4, 6, 8, 10, 12

Checking the debug info the data is definitely:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12

It’s just the drawing that’s out of timing with my actual data.

This is my code. I’m not sure what I’m doing wrong:

func countUpScore():
	var freedTimer = Timer.new()
	freedTimer.set_timer_process_mode(1)
	freedTimer.connect("timeout",self,"_on_freedTimer_timeout")
	freedTimer.set_wait_time(.3)
	add_child(freedTimer) #to process
	freedTimer.start() #to start

func _on_freedTimer_timeout():
	print("global score: ", str(globals.score))
	print("drawsci=ore: ", str(drawScore))
	if drawScore <= globals.score:
		drawScore += 1
		get_node("yourScoreLabel").set_text("Your Score: %s" % str(drawScore))

I’ve changed the line freedTimer.set_wait_time(.3) to have different values but no to avail, same issue.

Any advice would be appreciated.

Thank you.

Just tested this and it is working correctly on my end, all digits were displayed sequentially in the label.

ericdl | 2016-11-28 13:40

:bust_in_silhouette: Reply From: Jatz

change this part:

if drawScore <= globals.score:

to this:

if drawScore < globals.score:

this is a logic error on your part, each time the timer calls, it checks to see if the value is the same or below the global value, and then increases its value by one,

that means that even though it is on the same value, it increases by one.

Of course I can’t be sure about this until I look at your source but that would seem to be the problem, from my point of view.