[SOLVED] How timers actually work? Like how they count time?

How timers in gdevelop actually work and i know what they do i ask how

Like do they save current time and then we are comparing time saved on timer start with current time?
Or what?

You can look at the Javascript. You don’t need to understand Javascript, it’s filled with comments. I know the basics of Javascript.

You can use the search at the top with things like “time”
https://docs.gdevelop.io/GDJS%20Runtime%20Documentation/modules/gdjs.html

It seems to create lists of time starting at 0 that gets updated each frame before the events. It seems to add the elapsed time since the last frame. I guess this keeps everything in sync.

A couple of the key functions.

    //Timers:
    /**
     * Updates the object timers. Called once during the game loop, before events and rendering.
     * @param elapsedTime The elapsed time since the previous frame in milliseconds.
     */
    updateTimers(elapsedTime: float): void {
      for (const name in this._timers.items) {
        if (this._timers.items.hasOwnProperty(name)) {
          this._timers.items[name].updateTime(elapsedTime);
        }
      }
    }

/**
     * Notify the timer that some time has passed.
     * @param time The elapsed time, in milliseconds.
     */
    updateTime(time: float): void {
      if (!this._paused) {
        this._time += time;
      }
    }

That is more than i needed
THX

1 Like

You’re welcome. I love being able to see the source. It helps you understand things and be a little more efficient. It also helps when writing something in JavaScript.

I included the functions in case I wasn’t reading it correctly.