0 votes

Since we run in a loop at 60Hz, or 60FPS if you like, how do I do something at 1 second intervals?
(don't know how to format code here)

 var globalsleep = 1.0 - (1/60)
 var prevdelta = 0.0

        func _ready(): 
        # get ready now

    func _process(delta)
    prevdelta += delta
        if prevdelta >= globalsleep:
    print("prevdelta = ",prevdelta)
    prevdelta = 0.0

But there is always some time lost and prevdelta will be more than 1 second.

But that is strange because if I run and just print(" delta = ", delta) I see 1/60 or 0.0167

Something seems broken to me. I am using git master.

I hope someone can try to explain this but I think it's a bug. Or is there some kind
of global lock like python GIL? Which would mean that Godot is all in a single-thread.

Or am I misunderstanding some signficant design behavior?

asked May 16 in Engine by jitterbeetle (44 points)

Might not be what you're looking for, but you maybe could use a timer node set to 1 second. Not sure if that is more precise.

I will look at that but unless it uses some other mechanism the timer node would be coupled to the same timing mechanism and suffer the same symptoms.

There were some timing related commits recently so I need to pull, rebuild and retry.

1 Answer

0 votes

I imagine that there is some sort of rounding error going on. 1/60 is not exactly 0.0167, but a bit less: 0.01666666666666666666666... Therefore if you are adding 0.0167 every step, you will end up with 1.002, even if there are exactly 60 steps per second. If it is important that you arrive at 1.000 exactly, subtract the 2 milliseconds every 60th frame.

answered May 16 by camarones (87 points)

No. I can set globalsleep = 1.0 - (2/60) and makes no difference. It's easy to try it out and see it.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.