Wait command script call for title screen?

Hey folks,

I've done some poking around, and can't seem to find a script call that would work on the title screen.

I am setting up a custom main menu, and one of the commands is a "Quit to Desktop" option. I'd like to fade to black before it quits, however.

I am trying to do something like this:

$gameScreen.startFadeOut(30);
this.wait(30);
SceneManager.exit();

So far, I haven't been able to get this working. I can't use "this" since it is not in an event (it is being run from VisuStellaCore as a menu JS command), and while I know there are ways to get various game interpreters to run the command, I haven't gotten any to work with the "wait" command so far.

Removing "wait" just quits before the fade-out does anything.

Any help is appreciated!
You could create separate Script calls, after all, you are still using event commands in the middle of this.

Good luck
You could create separate Script calls, after all, you are still using event commands in the middle of this.

Good luck

I'm not too sure what you mean by separate script calls. The event commands (this.wait) are the part that don't work, since there is no event running the script.
You could create separate Script calls, after all, you are still using event commands in the middle of this.
Where?

it is not in an event (it is being run from VisuStellaCore as a menu JS command)
I don't know why, I had the impression that your title was personalized (made by events).
Sorry for the mistake.
Hey folks,

I've done some poking around, and can't seem to find a script call that would work on the title screen.

I am setting up a custom main menu, and one of the commands is a "Quit to Desktop" option. I'd like to fade to black before it quits, however.

I am trying to do something like this:

$gameScreen.startFadeOut(30);
this.wait(30);
SceneManager.exit();

So far, I haven't been able to get this working. I can't use "this" since it is not in an event (it is being run from VisuStellaCore as a menu JS command), and while I know there are ways to get various game interpreters to run the command, I haven't gotten any to work with the "wait" command so far.

Removing "wait" just quits before the fade-out does anything.

Any help is appreciated!
Since this is a simple command and nothing else is going to be running after it, you could do:
JavaScript:
$gameScreen.startFadeOut(30);
setTimeout(()=>SceneManager.exit(), 500)

this.wait() requires the interpreter so it would be $gameMap._interpteter.wait(). However, it issue is that it is running the script all at once so what you typed in will run immediately.

The timeout is fine because you don't have much going on for things to be out of sync (at least it doesn't sound like it for this). I don't use it often but it does work well at times.
Since this is a simple command and nothing else is going to be running after it, you could do:
JavaScript:
$gameScreen.startFadeOut(30);
setTimeout(()=>SceneManager.exit(), 500)

this.wait() requires the interpreter so it would be $gameMap._interpteter.wait(). However, it issue is that it is running the script all at once so what you typed in will run immediately.

The timeout is fine because you don't have much going on for things to be out of sync (at least it doesn't sound like it for this). I don't use it often but it does work well at times.

Hmm, this doesn't seem to work. It still just quits the game immediately with no fade.

EDIT: Actually, I set it to "5000" instead to test, and the delay is happening. The issue is that the fadeout is not happening.

I can only assume this means that $gameScreen.startFadeOut(30); cant be run on the title screen.

Is there some fade command that can run on the title screen?
I used this to solve:
JavaScript:
this.startFadeOut(30, false);

I don't know how it will work or how you included it in the title menu, but in my case I replaced this function:
JavaScript:
Scene_Title.prototype.commandQuit = function() {
    this._commandWindow.close();
    this.startFadeOut(30, false);
    SceneManager.exit();
}
I used this to solve:
JavaScript:
this.startFadeOut(30, false);

I don't know how it will work or how you included it in the title menu, but in my case I replaced this function:
JavaScript:
Scene_Title.prototype.commandOptions = function() {
    this._commandWindow.close();
    this.startFadeOut(30, false);
    SceneManager.exit();
}

This code doesn't do anything for me when run as a title command unfortunately. It is being run with VisuStellaCore
That was an example of the standard RMMZ menu, but it would need to be listed by a previous function.

try including this before "Exit":
JavaScript:
this.fadeOutAll();
That was an example of the standard RMMZ menu, but it would need to be listed by a previous function.

try including this before "Exit":
JavaScript:
this.fadeOutAll();
This gives the same error as if I used this.wait (TypeError: this.fadeOutAll is not a function).

I think it is just due to it not being run by an event (any this. command will not work, as there is no "this" running the command).
Sorry for the delay, I really couldn't do it directly...
I had to create a function to be called, the advantage is that it was possible to do it within the Plugin configuration itself:
1707892195538.png



JavaScript:
Scene_Title.prototype.commandQuit = function() {
    this._commandWindow.close();
    this.fadeOutAll();
    setTimeout(()=>SceneManager.exit(), 1000)
};
SceneManager._scene.commandQuit()

Edit:
I set it to 1000 milliseconds just to test, but I recommend lowering it to 700 or 600
this.wait(30);
FYI:
wait does not work as you assume it would.

There is a main game loop for updates when the game is running.
This game loop contains all events, all parallel processes and all movement routes and more.

The wait command simply tells that game loop "skip processing this element until xy".
That is why it reduces lag in a parallel process.
and it is aloso why it cannot work if the game loop is not running (before game) or if it is used with an object that is not part of the game loop (while the game loop contains a lot, it does not contain everything)
$gameScreen fade will only work if the scene updates Game_Screen; by default only the map and battle scenes do that. It will also not mark the scene as busy, which is necessary to, for example, prevent the title command window from re-opening.

As others have said, a similar kind of thing applies to the event interpreter wait call.

If you don't know what context is being used for the script call, you can either check it (e.g. console.log(this)) then adjust based on the result, or avoid context-dependence (i.e. this). E.g.
JavaScript:
const sc = SceneManager._scene;
sc._commandWindow.close();
sc.fadeOutAll();
setTimeout(
  () => SceneManager.exit(),
  sc.slowFadeSpeed() * 1000 / 60
);
I think it is just due to it not being run by an event (any this. command will not work, as there is no "this" running the command).
this doesn't necessarily have anything to do with events.

It's is a reference to the object running the current code - in the context of RPG Maker, there is always a this - the question, as caethyril described, is what kind of object it is.
$gameScreen fade will only work if the scene updates Game_Screen; by default only the map and battle scenes do that. It will also not mark the scene as busy, which is necessary to, for example, prevent the title command window from re-opening.

As others have said, a similar kind of thing applies to the event interpreter wait call.

If you don't know what context is being used for the script call, you can either check it (e.g. console.log(this)) then adjust based on the result, or avoid context-dependence (i.e. this). E.g.
JavaScript:
const sc = SceneManager._scene;
sc._commandWindow.close();
sc.fadeOutAll();
setTimeout(
  () => SceneManager.exit(),
  sc.slowFadeSpeed() * 1000 / 60
);

Wow, this worked perfectly, thanks!

I was completely out of my depth on this one for sure - and all for a minor cosmetic change haha.

Original thread: https://forums.rpgmakerweb.com/threads/wait-command-script-call-for-title-screen.165733/