0 Favourites

How accurate is "every X seconds"?

  • Is this event approximate, or fairly accurate? What I mean by that is that assuming the game is running at full speed (60fps?),

    1) would the timer be accurate to within miliseconds?

    2) would errors accumulate? Or if the system was busy of 2X seconds, would the event fire twice in quick succession, and "catchup" afterwards?

    3) If you say ran "every 1 second" say 1000 times (i.e. let the event fire 1000 times), would the elapsed time be 1000s +/- <1s?


  • The lowest you could set it would be about 0.016 (or 1/60) seconds. That and anything lower would be the same as a "every tick" condition.

    Back to the question as to if it's accurate: it runs if the time passed since the last time it ran is greater than or equal to the value you used.

    Here's what "every 1.0 seconds" does:

    global number old_time=0

    +old_time + 1.0 >= time:

    -- set old_time to time

    -- do actions

    3) It will likely be a bit lower than 1000. Of course you could test this if you wanted.

  • Ha, so it will always be slightly longer than 1s, so it will accumulate a positive error over time.

    I assume I need to do something different, e.g. get the timestamp of now, then check every tick if the current time stamp is >= 1s different, then 2s differnt etc. This will not have the accumulative error.

    Looks like System.wallclocktime might be what i need? Im hoping this is similar to the unix timestamp in ms.

  • 'Every X seconds' should not accumulate any significant error over time. If it is a tiny bit late due to only checking every 0.016 seconds, it subtracts the lateness from the next run, so the next run is a tiny bit quicker to compensate. While this introduces an (almost undetectable) amount of variation in the duration between individual runs of 'Every X seconds', it means in the long run it's actually pretty stable.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Perfect! Ill stick with that then - nice.


Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)