0 Favourites

# Accurate Time

• 12 posts
• I created an event like this using the System-Time expression:

Every 1 seconds set text to Time.

I thought this would create a textbox shows a value which increments every second (1,2,3...). But in practice, the textbox value has a lag and values are increasingly off (1.008, 2.013, 3.033...). Why is there a lag and why does it get worse and worse?

Thanks from a newbie.

You should replace the event with

Every tick >

-> Set text to str(varTime)

Someone correct me if there's anything wrong here

• Thanks for the reply, 7Soul. I also suspected that dt might solve my problem. However, your suggestion gives me a continuous counter. I'm looking for a counter that increments by seconds. And I'm not sure why I would use the expression 1*dt. It seems redundant. Did you mean something else?

I'm curious as to why Every X Seconds doesn't work. Is it a realtime timer, or is it an approximation? I feel like I'm under some basic misapprehension.

• Try int(1*dt) I put the 1 just as a good practice. Changing it to 1000, for instance, would give you the milliseconds

• Well, I read the dt tutorial again and used their example to do some testing. I created 3 textboxes and the following events:

<img src="http://i.imgur.com/4KekI.jpg" border="0" />

Which produced the following results.

<img src="http://i.imgur.com/SxkC1.jpg" border="0" />

You can see the timers which rely on "every tick" are in synch, whereas the one which relies on "every x seconds" is lagged (until the numbers from the right of the decimal carry over and then it catches up).

This was unexpected behavior for me. I guess I need a better understanding of frames. I am interested in this problem because I am creating a musical game where time is very important.

• stupid question....why or better what for do you need a timer, that is exact to a milisecond?

• I am hoping to make a game where people will follow along to the tempo of music and tap buttons at the same time that the notes are played.

• This is because a tick is faster than a second, so these events will run at different times. A tick, at 60 frames per second, happens 60 times in a second, as you would expect.

But now, tell me what you want to happen, because I don't understand :I

• It think ticks are client dependent, ie a tick on a high speed four core processor might be shorter than on an old x86...

But maybe Ashley could answer this.

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I think I've got it now. Thanks for your help!

• It think ticks are client dependent, ie a tick on a high speed four core processor might be shorter than on an old x86...

But maybe Ashley could answer this.

Yes, ticks vary depending on your system speed and browser speed. That's why you should use dt in your events, to account for that variance and provide a consistent gameplay

• Adding dt like that isn't actually perfectly accurate, it will accumulate small errors over time due to the nature of floating point addition.

Construct 2's runtime does its timing with higher precision to avoid that issue, so 'every 1 second' should actually be more accurate than adding 1 to dt every second. You should also just round the returned time because a game running at 60 fps only runs a tick every 16ms which means the time can be anything within 16ms of its intended time.

The problem with accuracy getting worse over time with 'Every X seconds' was actually a small bug - I've fixed it for the next build.

• 12 posts