How can i auto close / crash my game?

I'm working on an ending system in my game where depending on what you do, a variable will go up or down, is there a way i can make it where at the end of the game, if the variable = 100, it will close or crash the game, then overwrite the players save file to spawn them in a room they cannot leave, forcing them to delete that save, or load a different one? Thanks!
I mean, a parralel run common event could do this (at least the variable part, not sure about the overwrite save part but there's probably a script call for it). The real question is, why?
I mean, a parralel run common event could do this (at least the variable part, not sure about the overwrite save part but there's probably a script call for it). The real question is, why?
i just thought it would be funny that doing too many bad things will result in the game doing this
To auto-quit the game, use this script:

Code:
SceneManager.exit()

To auto-crash the game:

Code:
throw Error("LOL")

To force-save:

Code:
const savefileId = $gameSystem.savefileId();
savefileId && DataManager.saveGame(savefileId);
Will do nothing if game hasn't been saved before.
To auto-quit the game, use this script:

Code:
SceneManager.exit()

To auto-crash the game:

Code:
throw Error("LOL")

To force-save:

Code:
const savefileId = $gameSystem.savefileId();
savefileId && DataManager.saveGame(savefileId);
Will do nothing if game hasn't been saved before.
Im very new to RMMZ, and rpg maker in general, how do i import scripts?
You'll want to do this in a common event, so open up the database. Set the trigger to Parallel and a switch to trigger it. You'll need to turn your switch on at some point in your game, at which point the event will start running. Then create a conditional branch and if variable x >= 100.
The event will run in the background and continmously check to see if variable is 100 or greater. Then it will run everything under that conditional branch.

Scripts are found on the third tab in the eventing menu. Open it up and enter the script call exactly as Aerosys wrote it.
1724403291422.png
Be careful!! If you save the game in an event, that also crashes the game, than that event will continue running when the game is loaded, starting at the point where it was saved, meaning the game will crash again on load.

I wouldn't know a good solution to do this... No matter how you force the save, your event will be finished after load.
For the "only quit if just saved" thing:
You can define, and check for, a flag on $gameTemp:
  • Script: $gameTemp.quitNow = true;
  • Conditional Branch -> Script: $gameTemp.quitNow
$gameTemp is not saved, so this lets you distinguish between "just saved" and "just loaded". E.g.

◆Script:$gameTemp.quitNow = true; ◆Open Save Screen ◆If:Script:$gameTemp.quitNow ◆Return to Title Screen ◆ :End
Thanks to everyone who replied!!!

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-auto-close-crash-my-game.171344/