MZ Question on update() function

I'm trying to make my own parallel method in javascript (same as parallel event) on Scene_Map. However, on Scene_Map's update() method, it seems like it executes console.log per frame. What will I do so that it executes console.log per 60 frames?

And also, is there a thread that answers small questions like this? I don't think this question deserves its own thread. Thanks in advance!

Here's my code:

JavaScript:
_alias_scene_map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function()
{
    _alias_scene_map_update.call(this);
    if(Input.isTriggered("openGambitMenu")) SceneManager.push(SceneGambit);
    console.log('what');
}
There's a thread for "small" JS questions, e.g. context-specific script calls:
I don't think this question belongs there, though! It's OK to have a thread for this. 👋


You can track how many frames it's been since the last call and only call when that hits a certain value, e.g. (untested):
JavaScript:
// IIFE to avoid potential scope conflicts
(() => {
  // store current method in a local variable
  const alias = Scene_Map.prototype.update;
  // override method
  Scene_Map.prototype.update = function() {
    // invoke alias with arguments
    alias.apply(this, arguments);
    // initialise counter if needed (lazy)
    this._myFrameCounter ??= 0;
    // update/check counter
    if (++this._myFrameCounter >= 60) {
      // reset
      this._myFrameCounter = 0;
      // do the things
      console.log('hello!');
    }
  };
})();
Alternatively you could initialise the counter in the scene's create method or something.
There's a thread for "small" JS questions, e.g. context-specific script calls:
I don't think this question belongs there, though! It's OK to have a thread for this. 👋


You can track how many frames it's been since the last call and only call when that hits a certain value, e.g. (untested):
JavaScript:
// IIFE to avoid potential scope conflicts
(() => {
  // store current method in a local variable
  const alias = Scene_Map.prototype.update;
  // override method
  Scene_Map.prototype.update = function() {
    // invoke alias with arguments
    alias.apply(this, arguments);
    // initialise counter if needed (lazy)
    this._myFrameCounter ??= 0;
    // update/check counter
    if (++this._myFrameCounter >= 60) {
      // reset
      this._myFrameCounter = 0;
      // do the things
      console.log('hello!');
    }
  };
})();
Alternatively you could initialise the counter in the scene's create method or something.
Thanks! I understand now how to do this. Thanks again!

Original thread: https://forums.rpgmakerweb.com/threads/question-on-update-function.146320/