Save on Shutdown / Return to title Script

Hello everybody,

In my game I want the player to not be able to save. Instead the game should autosave whenever the player decides to shutdown the game or returns to title. The idea behind it is that the player has to life with his decisions and their consequences and that the game should feel more immersive.

I have been searching the web for a rather simple script, which would automatically save the game when the player press shutdown or return to title but didn't really find something except for

a rogue-like-script that did not work out for me since it generated a new "resume" option in the title menu and deleted the savegame whenever it was loaded.

I need a script which creates a save file when the player shuts down the game or returns to title without the usual save menu. Instead the game should just create a savegame in the first slot without asking or telling the player and then shutdown or return to title. The save file should not be deleted when the player presses continue but just be overwritten next time he quits the game.

I hope I described clear enough what I need and I thank everybody for reading this request! 🙂
If it's strictly rgss3 only, i doubt it's do-able, because the player can always click that [X] button to close the game directly.

If you code the auto save on closing program (not sure if it's possible without some external source).. there's a good chance that, during crash, the game will save a bad save over the existing ones and the player will have to start all over for an error not done by him/her.

And well, there's always the "pull the plug" option.. lol!

But well, if all of that doesn't matter to you, i'll see if i can put together a short snippet to make it works.

But if you have other scripts that modify title/menus/save, there maybe some conflict.

Let me know within today before i set to work on it.
The best way of doing so is the Minecraft implementation.

In Minecraft I think it's autosaving the game rapidly.

So, maybe you would like to do something like this :

Code:
Thread.new(){loop{DataManager.save_game(0) if SceneManager.scene_is?(Scene_Map); sleep(10)}}
It should autosave the game every 10 seconds, asynchronously.
Thanks for your fast answers, guys. Yes I do have some scripts already that modify the menu. And I actually didnt thought about players clicking the X 😛

But I like the idea of KockaAmiralac, sounds like it could solve the issue with game crashes or players pulling the plug xD

I'll try that out right now.

Okay I tried it out. I made a new script below Materials and above Main and pasted your script in there, KockaAdmiralac. Unfortunately it does not work.

Do I have to use that script in a event in order to work?

Maybe it doesn't because I deletet my autosave file? If so where do I get a new one?

Thank you for your effort!
Ok, try this code :

Thread.new(){loop{SceneManager.call(Scene_AutoSave) if SceneManager.scene_is?(Scene_Map); sleep(10)}}class Scene_AutoSave  def main    DataManager.save_game(0)    SceneManager.return  endendWorks for me, at least...

NOTE: This will auto-save the game in the file Save01.rvdata2

If you want it to save to some other index, change the 0 in DataManager.save_game(0) to something else
Minecraft Save File corruption is a well known issue.

A lot of the world developers went for a "back up" file solution in the end.

So nope, i don't think it solves the crash problem.

But, well.. there's a way to remove that pesky close button actually.. sort of...

Just need to call a win32api code to do so but...

... might turn out with an ugly black empty border. i did that before by removing the whole game frame(not the button but the whole game frame), and well.. turns out ugly even if it's working.. lol! ended up with a black square line around the game screen. Might be my calculation miss, i hate math. So a little tinkering might get the code right. 😛

But even if i am able to remove that X button for you, you will still need to find a way to disable Alt+F4 😛

And i'll need those menu-modifying script name/link you are using since what you are requesting here is something close to an overwrite, so save/load menus modifying scripts has a high chance of conflicts with such a huge modification in how save/load works. I'll need to modify at least 4 sections from what you requested. Scene_File(probably), Scene_Menu(need to remove "save"), (Scene_Save probably not needed anymore, so i am leaving that out), Scene_Load(modify to direct loading the game), Scene_End(Need to modify the return to title command to save your game), and the DataManager module (probably, depends on how the game check for file before saving).

Make that 5 if you want the game to save during map change. (Game_Map)

Any script you use that uses those classes/module might not be compatible any more. (and that includes some of the future scripts you wanted to use)

Goto your script editor, and press ctrl+shift+f, a window will pops up, type in those names above and see if any other custom scripts you use are in the search list. If yes, means they might have a high chance of not working after this modification.

If you are fine by that, let me know, only have like 4 hours left of my free time. Won't see me here tomorrow. 😉

Why am i helping to code a game that i might turn out hating it? lol!
@MeowFace : Hmmm... didn't know about that... Never had that experience with Minecraft...

Well, there is an another way.

You can make TWO threads, one is called on every 10 seconds, other on every 105 seconds (not 100, because then they would intersect each other).

And they should save in two different files, and calling two different scenes

Also, the DataManager.save_game should then be modified to backup from the old file if the new one has been corrupted, and not just delete the new one.

If you want more security, you can make THREE threads an so on...
The problem with a constant autosave is, you don't even need a crash to corrupt it.

Saving alone can corrupt the save file, autosave just makes the chances higher, and constant autosave = always on the risk.

Saving while exiting the game might corrupts it, saving during a black-out will 100% corrupts it(this happen to all software), and needless to say, saving when the game crashes corrupt the file, saving when windows update decided to restart your pc can cause file corruption too. 

So.. with the Map editor's file corruption on save, now we need to deal with rgss player's file corruption on save. 😛

Yes, i hate that "save on exit" in RMVA, that gives such a high chance of, "omg! file corrupted, need to remake the game!" lol!

And that test play button, too. Be careful of it. 😀

Edit:

Since he's not replying any sooner and i don't have much free time left. He'll have to use your solution instead unless someone else drops by and help out.
That's why I was suggesting two threads.

One will save on every 10 seconds.

If it's successful, save file will be saved.

If it's unsuccessful, save file will be corrupted.

If the file is corrupted, it'll be replaced by the second thread's save file.

So there is a chance of corrupting ALL the saves, but much less than with one thread.

If you don't understand what I ment, imagine this.

Spoiler
Second 0:

Thread 1: sleeping

Thread 2: sleeping

Second 10:

Thread 1: saving to the Save01.rvdata2

Thread 2: sleeping

Second 105:

Thread 1: sleeping

Thread 2: saving to the Save02.rvdata2

Second 500:

Thread 1: saving, but BLACKOUT happens while saving

Thread 2: sleeping

After starting the game again:

Save01.rvdata2: corrupted

Save02.rvdata2: still OK, but a bit back in time.

So you can replace Save01.rvdata2 with Save02.rvdata2 if you see it's corrupted
Doesn't matter really, since i don't have any free time on hand any more.

You might want to implement the backup method for him and hr1300 will need to include information on how to recover backup files on his game manual.

He will still need this code for disable exit to reduce the chances of a corrupt file:

This script fully hides the window's border(to prevent closing from clicking the logo) and disabled Alt+F4

#==============================================================================# ■ Meow Face Exit Canceler#------------------------------------------------------------------------------# Hide window's Border, Disable Close Button and Alt + F4#==============================================================================# How to Use:# Plug & Play, Put this script below Material and above Main#==============================================================================MF_GPPSA = Win32API.new('kernel32', 'GetPrivateProfileStringA', 'PPPPLP', 'L')MF_FW = Win32API.new('user32', 'FindWindow', 'pp', 'l')MF_SCL = Win32API.new('user32', 'SetClassLong', 'lil', 'i')MF_SWL = Win32API.new('user32', 'SetWindowLong', 'iii', 'i')MF_TITLE = " " * 256MF_GPPSA.call('Game','Title','',MF_TITLE,256,".\\Game.ini")MF_TITLE.delete!(" ")MF_HWND = MF_FW.call('RGSS Player', MF_TITLE)MF_SCL.call(MF_HWND, -26, 0x0200)MF_SWL.call(MF_HWND, -16, 0x14000000)

But please keep in mind that i myself hate this code for taking away close button and Alt+F4, 

So credit is not needed as i don't want any blames for taking away their freedom of exiting the game when they want to. 😛
Hey guys,

wow you really had some nice ideas. Thanks alot!! I will try them out now.

@MeowFace: Thank you for your script but I want the player to able to leave the game whenever he feels like it. I just want the game to save before 😛

But I guess the minecraft method is allright as long as I use multiple threads. Of course a corrupted savegame is always really annoying and bad

but I think I'd rather take that instead of having black borders since rpg maker games do not look that great to begin with.

I'll give you some feedback after I tested both of your suggestions.

Huge thanks again!!

Okay so I tested your script, KockaAdmiralac. It works great! Exactly what I need! Thank you!!

Although the game freezes for a very short moment whenever it saves but I guess that is due to technical reasons of rpg maker.

Anyways I thank both of you for taking the time and spending effort on my problem 🙂

Original thread: https://forums.rpgmakerweb.com/threads/save-on-shutdown-return-to-title-script.44617/