MZ Game_Timer: Pause and Resume

I tested it on RMMV and it worked perfectly, I don't have the RMMZ to test, if anyone can check it for me.

Update: Option to hide timer included.

In theory I know it works, but I don't remember if there might be some incompatibility:
JavaScript:
/*:
 * @plugindesc Pause GameTimer
 * Version: 0.2 - Test only
 * @author DevWithCoffee
 *
 * @help Plugin: Game_Timer-Pause.js
 *
 * Pause and Resume GameTimer
 * Compatibility: MV and MZ
 *
 * Commands:
 *          $gameTimer.pause()
 *          $gameTimer.resume()
 *
 * @param Hide timer
 * @type Boolean
 * @desc Hide timer when paused
 * @default false
 *
 */
(() => {
    var parameters = PluginManager.parameters("Game_Timer-Pause");
    Game_Timer.prototype.initialize = function() {
        this._frames = 0;
        this._working = false;
        this._pause = false;
    };

    Game_Timer.prototype.pause = function() {
        if (parameters['Hide timer'] == "true") {
            this._working = false;
        }
        this._pause=true;
    }

    Game_Timer.prototype.resume = function() {
        if (parameters['Hide timer'] == "true") {
            this._working = true;
        }
        this._pause=false;
    }

    Game_Timer.prototype.update = function(sceneActive) {
        if (sceneActive && this._working && this._frames > 0 && this._pause == false) {
            this._frames--;
            if (this._frames === 0) {
                this.onExpire();
            }
        }
    };
})();
I got more likes than feedback?! :LZYshock:
Since no one is willing to test the Script in the RMMZ I was able to test it myself, it's functional.
I intend to include some more customization options and then create a topic to make it available.
Nice plugin, I made this one myself for someone a while back when they needed the same functionality and I did it pretty much exactly the same way.

What I will say is that since all you're adding to initialize and update are an extra property and a logic check, it's entirely possible to alias these instead of overwriting them, which offers better compatibility with any plugins that might also affect the timer, and I suggest dropping var entirely and using let/const:

JavaScript:
(() => {
    const parameters = PluginManager.parameters("Game_Timer-Pause");
    _Game_Timer_initialize = Game_Timer.prototype.initialize;
    Game_Timer.prototype.initialize = function() {
        _Game_Timer_initialize.call(this);
        this._pause = false;
    };

    Game_Timer.prototype.pause = function() {
        if (parameters['Hide timer'] === "true") {
            this._working = false;
        }
        this._pause = true;
    }

    Game_Timer.prototype.resume = function() {
        if (parameters['Hide timer'] === "true") {
            this._working = true;
        }
        this._pause = false;
    }

    _Game_Timer_update = Game_Timer.prototype.update;
    Game_Timer.prototype.update = function(sceneActive) {
        if (!this._pause) {
          _Game_Timer_update.call(this, sceneActive);
        }
    };
})();
Very good, even I never studied how to really develop Plugins, your explanation really helped me to understand better how it works.

I don't see the need to continue developing as yours works perfectly and without the risk of incompatibilities.

Thanks for the feedback.
Very good, even I never studied how to really develop Plugins, your explanation really helped me to understand better how it works.

I don't see the need to continue developing as yours works perfectly and without the risk of incompatibilities.

Thanks for the feedback.
I'm almost worryingly obsessed with refactoring my code and making it as concise and efficient as possible, so I've learned quite a lot of useful tricks for that over the years. 🙂 Glad I was able to help! And thanks for my 5000th reaction. <3
I'd be careful with implicit globals like _Game_Timer_initialize in Trihan's quick example. It's safer to declare those with let/const like the other stuff: doing so restricts references to them from outside, but helps avoid accidental conflicts.

For a "full" plugin, a common approach is to use one or two global variable(s) and define all the plugin stuff on those: that makes everything globally accessible and minimises naming conflicts. E.g.
JavaScript:
// define global author namespace (if it doesn't already exist)
window.MyNamespace || (window.MyNamespace = {});
;(() => {
  // define plugin subspace
  window.MyNamespace.TimerPause = {};
  // define plugin property
  window.MyNamespace.TimerPause._Game_Timer_initialize = Game_Timer.prototype.initialize;
})();

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/game_timer-pause-and-resume.152178/