Random beginner-question: yield until next OS-time-second (or trigger on each)

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

Hi everyone,

I have a clock set up showing the OS’s hours, minutes and seconds. What I need is an event (maybe a signal) to trigger on every tick of the OS-time’s second.

Or: have a trigger (a button-press) yielded until the next OS-time second tick.

Im working on a backwads-running timer, showing the remaining time until that entered by the user. Calculating the remaining seconds I can have that timer start immediately, but as it should reach 0 exatly when the time is reached, I need it to start with the next clock-second…

The docs show get_system_time_secs, which seems promising, but I wouldn’t get anything working with it. Any suggestions?

:bust_in_silhouette: Reply From: exuin

I don’t think this is possible right now in Godot since normally people just use timers for this. But you can suggest it on the proposals GitHub.

It basically boils down to having a timer running in sync with the OS-time…

A built-in function for a timer-countdown towards a time and date, maybe even years away, would indeed be cool, wouldn’t it? (“2y, 3m, 1w, 4d, 17h, 25min, 39sec to go…”)

EDIT:
So yes, I’m trying to have my timer start exactly when the next OS-time-second kicks in.
For now I’m thinking of “compare the entered time with the OS-time and fire when they match”. I’ll see how this could be done and be back when I found a way…

pferft | 2021-04-22 09:12

:bust_in_silhouette: Reply From: pferft

Thanks to golddotasksquestions on reddit for this:

“trigger something repeatedly every second, in sync with OS-time-second”
Like print “X” every second, in sync with OS time.

var last_second = OS.get_time().second

func _process(delta):
	var time = OS.get_time()
	if time.second != last_second:
		print("start of a new second")
	last_second = time.second
	print(time.second)