Silently saving and then closing the game?

MagentaGiratina

Distortion World Enthusiast
Member
Joined
Jun 16, 2019
Posts
46
I'd like to do some wall-breaking type stuff where characters get mad at the player and boot them out of the game, making sure to save the game beforehand so the player gets the effect of the fourth wall not protecting them without them losing any data. Only problem is, while I assume it's possible, I don't know of a way in Essentials or RGSS to silently save the game and then make it close itself. What I've been doing is going back to the title screen or purposely running scripts that don't exist so the game errors itself out, but I'd prefer it to just seamlessly close after silently saving, especially since in what I'm doing right now, the game isn't saving itself because I don't know of a way to silently save. In short, I'm looking for ways in Essentials/RGSS to:

* Make the game close itself (ideally closing the window. Not essential, but would be nice)
* Save the game without needing input from the player or showing anything visibly.
 

NettoHikari

Trainer
Member
Joined
Jan 4, 2019
Posts
97
You can use the method "pbSave" in a Script box to silently save the game, and then you can do what the load screen does for its "Quit Game" option, which I think is just "$scene = nil" in another Script box. Here's the thing about pbSave though: if it's called in the middle of an event, it will save in the middle! So if you're planning on doing:
Ruby:
pbSave
$scene = nil
then when the player opens the game again, it'll start just after "pbSave", closing the game again. The player would never be able to open their save again.
You'd have to circumvent that by setting some kind of "flag" that prevents "$scene = nil" from happening if it already happened once, but the flag can't be in the save data because it won't get saved when the game quits. I found the following commands to work:

where it's basically creating a dummy file called "reload.txt" in the player's save folder before quitting, then checks if that exists when the game starts up again. You might want to put another "pbSave" in the "Else" section so that the dummy file isn't needed again.
 

MagentaGiratina

Distortion World Enthusiast
Member
Joined
Jun 16, 2019
Posts
46
Ok... I'll try that. What I was specifically thinking of doing would be something like this:

Text: I've had it with you, \PN! This is what you get for being such a jerk!
Self Switch A set to on
Game saved
Nil

The event page after Switch A is on would be an autorun event, with the intent of showing more text or something after the player rejoins. Would that work? If not, how would I do something like that?

Not in code notation because I'm on mobile and it isn't working for me.
 

NettoHikari

Trainer
Member
Joined
Jan 4, 2019
Posts
97
In the sample code you wrote, it would still get stuck on these two lines:
Code:
Game saved
Nil
Because once the player runs the game again, the game remembers that it was about to execute "Nil", which it does, force closing again. Even if you changed the code to look like:
Code:
Self Switch A set to on
Game saved
Nil IF Self Switch A is ON
Self switches are part of your save data, so when pbSave runs, it saves the fact that Self Switch A was set to ON just a line before. So after the game exits once and the player reloads, the save data restores Self Switch A to ON, and the game runs "Nil IF Self Switch A is ON", which is the same as before. This is why I said that the "flag" you need to check if a player is reloading their game from being force closed once cannot be stored inside the save data, but rather somewhere outside it. If you want to show more text after the player rejoins, simply edit the part where I wrote "Text: Success!" in my code above.
 
Top