MV Wait Time between losing and Game Over Screen (Need help)

I really could use some help with this piece of code I'm trying to do. I've been trying to get it solved for quite awhile now with no luck. I'm trying to make it so when the last actor is defeated, the game waits one second before moving to the Game Over screen. I know this is the piece of code I need to modify:

JavaScript:
BattleManager.processDefeat = function() {
    if (this._canLose) {
        this.replayBgmAndBgs();
    } else {
        AudioManager.stopBgm();
    }
    this.endBattle(2);
};

I've tried using the code below (at the suggestion of another user), and it didn't work (I even set the count to 600 for testing). I must be missing something about how to write the code for wait time, but I don't know what. Help is greatly appreciated.
JavaScript:
BattleManager.processDefeat = function() {
    if (this._canLose) {
        this.replayBgmAndBgs();
    } else {
        AudioManager.stopBgm();
    $gameTroop._interpreter.wait(600);
    }
    this.endBattle(2);
};
I think it is mostly this.wait(600).
but if it's inside a battle that counts, maybe you can do "can lose"
where you fade out the screen over 600frames and than "Game Over"
as alternative?
Those script calls are for event interpreters, i.e. the part of the engine responsible for running code corresponding to event commands. They won't work here, because the BattleManager is its own system that updates every frame, and it skips the interpreter update if the battle is ending.

One option may be to find a plugin that lets you run an event at the end of a battle, before the victory/defeat phase starts, e.g. Hime End Phase Triggers?
I think it is mostly this.wait(600).
but if it's inside a battle that counts, maybe you can do "can lose"
where you fade out the screen over 600frames and than "Game Over"
as alternative?
It's in battle that the wait should be applied. It's supposed to be during the defeat process.
Those script calls are for event interpreters, i.e. the part of the engine responsible for running code corresponding to event commands. They won't work here, because the BattleManager is its own system that updates every frame, and it skips the interpreter update if the battle is ending.
Ah, so I'm trying to run a piece of code that gets ignored because the BattleManager is seeing the Battle has ended and thus doesn't see that line of code right?
One option may be to find a plugin that lets you run an event at the end of a battle, before the victory/defeat phase starts, e.g. Hime End Phase Triggers?
"the game will immediately go to victory or defeat processing"
The defeat process does the fade out to the Game Over screen right? That's where I'd want to insert a wait period as part of that processing. So the game should see that the last actor is defeated. It fades the BGM out, waits 60 frames, then fades out to the Game Over Screen.
I'm gonna give the plugin a try and see if that helps.
Ah, if you want to extend the duration for which the game is in a faded-out state, AFTER the defeat message, then that will probably need a different approach. Something like this, maybe?
Spoiler: plugin code
JavaScript:
/*: 
 * @target MV
 * @plugindesc Increases time faded out for battle -> gameover transition.
 * @help Free to use and/or modify for any project, no credit required.
 * https://forums.rpgmakerweb.com/index.php?threads/150986/
 */

// patch - initialise delay counter
void (function(alias) {
  SceneManager.initialize = function() {
    alias.apply(this, arguments);
    this._transitionDelay = 0;
  };
})(SceneManager.initialize);

// patch - check for delay
void (function(alias) {
  var isDelaying = function() {
    if (SceneManager._transitionDelay)
      return --SceneManager._transitionDelay > 0;
    return false;
  };
  SceneManager.isCurrentSceneBusy = function() {
    return alias.apply(this, arguments) || isDelaying();
  };
})(SceneManager.isCurrentSceneBusy);

// patch - apply delay
void (function(alias) {
  var shouldDelay = function() {
    return SceneManager.isNextScene(Scene_Gameover);
  };
  Scene_Battle.prototype.stop = function() {
    alias.apply(this, arguments);
    if (shouldDelay())
      SceneManager._transitionDelay = 60;
  };
})(Scene_Battle.prototype.stop);
I did a quick test and this seemed to work for me, but there may be a neater way to do it. 😴
Ah, if you want to extend the duration for which the game is in a faded-out state, AFTER the defeat message, then that will probably need a different approach. Something like this, maybe?
Spoiler: plugin code
JavaScript:
/*:
 * @target MV
 * @plugindesc Increases time faded out for battle -> gameover transition.
 * @help Free to use and/or modify for any project, no credit required.
 * https://forums.rpgmakerweb.com/index.php?threads/150986/
 */

// patch - initialise delay counter
void (function(alias) {
  SceneManager.initialize = function() {
    alias.apply(this, arguments);
    this._transitionDelay = 0;
  };
})(SceneManager.initialize);

// patch - check for delay
void (function(alias) {
  var isDelaying = function() {
    if (SceneManager._transitionDelay)
      return --SceneManager._transitionDelay > 0;
    return false;
  };
  SceneManager.isCurrentSceneBusy = function() {
    return alias.apply(this, arguments) || isDelaying();
  };
})(SceneManager.isCurrentSceneBusy);

// patch - apply delay
void (function(alias) {
  var shouldDelay = function() {
    return SceneManager.isNextScene(Scene_Gameover);
  };
  Scene_Battle.prototype.stop = function() {
    alias.apply(this, arguments);
    if (shouldDelay())
      SceneManager._transitionDelay = 60;
  };
})(Scene_Battle.prototype.stop);
I did a quick test and this seemed to work for me, but there may be a neater way to do it. 😴
Wow this is really close! The only issue I'm now running into is the scene fades to black, THEN it does the wait before displaying the game over. I want it to delay the fade out (I apologize if I wasn't clear the first time. Sometimes it's difficult to put to words what I see in my head). If I understand right,
Code:
    return SceneManager.isNextScene(Scene_Gameover);
is the part I want to change. If I want to delay the fade out, I want to change the Scene from Gameover to EndBattle right, or is it a different tag I use?
Ah, I misunderstood. So you want something like this, right?
  • "Party was defeated" -> close message -> wait 60 frames -> fade out.
This'll need a different approach because it targets a different set of methods.

I did a quick test and this seemed to work, though I might've missed something:
Spoiler: plugin code v2
JavaScript:
/*: 
 * @target MV
 * @plugindesc Adds delay between closing the battle defeat message and fade-out.
 * @help Free to use and/or modify for any project, no credit required.
 * https://forums.rpgmakerweb.com/index.php?threads/150986/
 */

// patch - apply delay
void (function(alias) {
  BattleManager.processDefeat = function() {
    this._endingTimer = 60;
    alias.apply(this, arguments);
  };
})(BattleManager.processDefeat);

// patch - check for delay
void (function(alias) {
  BattleManager.updateBattleEnd = function() {
    if (!$gameMessage.isBusy() && (!this._endingTimer || !--this._endingTimer))
      alias.apply(this, arguments);
  };
})(BattleManager.updateBattleEnd);
Hopefully that's more like what you wanted~ 👋
Okay so I was writing up a big ol' wall of text to help figure out why the new code wasn't working......all to find out I had turned the plugin off temporarily. Once I turned it on it worked perfectly! Just as I was hoping it would. Thank you so much for the help and your patience.
You're welcome, happy RPG Making~ 😂

Original thread: https://forums.rpgmakerweb.com/threads/wait-time-between-losing-and-game-over-screen-need-help.150986/