How do I create an Aggressive Autosaving & Conditional Branch to check saves?

Hey there folks,

The other day, not so long ago, I saw this thread was posted.
In summary, the user created an autosave system using the basic script commands that automatically overwrites the currently active save file, however it removes any data in save slot 1 (so basically, you can't save to save slot 1, if I understand him correctly)

The base idea of autosaves that overwrite the currently active save file is the functionality I want, however, I would like to let users use save slot 1.
In order to compensate for the possible error of attempting to save to a save file that hasn't been defined yet, my plan was to effectively force players to create a save at the start of the game. So I suppose that leads me to my questions:

1) How would I modify this to fit my needs? (source: from above linked thread)
Code:
var AutoSave = DataManager.lastAccessedSavefileId();
$gameSystem.onBeforeSave();
if (DataManager.saveGame(AutoSave)) {
  StorageManager.cleanBackup(AutoSave);
}
StorageManager.remove(1);
StorageManager.cleanBackup(1);
I'm certain I just remove the "StorageManager.remove(1); StorageManager.cleanBackup(1);", but I am a dummy when it comes to these things so I just want to confirm this is right.
[question 1 has been solved.]

2) What script can I use in a conditional branch to check to see if a save file has been written?


Thank you so much for your help as always.
I'm certain I just remove the "StorageManager.remove(1); StorageManager.cleanBackup(1);", but I am a dummy when it comes to these things so I just want to confirm this is right.
Yeah, just remove those two lines and that should do it.

The MZ/MV script call list has "DataManager.isAnySavefileExists()", but considering its nature it will return false if you start a new game while already having a save file, which could mess things up. So as far as I'm concerned, there isn't really a way around that besides putting a warning before opening the save menu.

Some save-related script calls which could probably be useful for this seem to be MZ exclusive, unfortunately.

1693366614409.png
Hey! Nice to see you here!
Thanks for the reply. At least I can strike question 1 from the list.

I hope to find the solution to question 2 😅
The MZ/MV script call list has "DataManager.isAnySavefileExists()", but considering its nature it will return false if you start a new game while already having a save file, which could mess things up.

Hmmm, that script works for me even if I start a new game (at least in playtest). Or maybe I don't understand something? Or if you want to check a specific slot, it's StorageManager.exists(X)

EDIT: Oh, and if you just want to make sure that a save exists, you can use that script in your first post to just save in a specific slot (instead of that var Autosave just save to a specific ID). Then you'd know for sure that a save exists without having to ask the player to save?
You're very welcome!

that script works for me even if I start a new game
The "DataManager.lastAccessedSavefileId();" variable always defaults to 1 no matter what (in MV at least), so even if you don't save at all, it'll still save and do it in slot 1. It could probably be changed by going through the default code, but that's out of my reach.

if you want to check a specific slot, it's StorageManager.exists(X)
That could be helpful. Weird how this isn't included in the Script Call list.
@rpgLord69 Thanks for the reply!
How would I go about implementing that?

And the one thing I am wondering about your edit;
How would the game account for new, different saves?
Say for example either situation A) Big brother and little brother play the same game, so when starting little brother starts a new save when big brother has already been playing, we don't want the autosave to overwrite big brothers save when creating a new slot for the game to autosave to.
Situation 😎 Much the same, but instead the same player decides to start a new game. Still wanting to keep the old save and not overwrite it, when starting the new game it should save to the next available slot.
So basically, if it were to be more automatic without the player manually creating a save at the start of the game, what would be the proper script to ensure that the game writes to the next available save slot?

Hmmm...my game also has a limited number of save slots, and so maybe if it automatically always wrote to the "next available" couldn't that also cause problems with the limited save slots?
I feel like my original idea about the game telling the player to create a new save is the better options because if they can't create a new save, then there will be no problems with the limited slots. Since creating the save slot would be set up through a conditional branch, I could theoretically allow for saveless play throughs by simply asking when the player exits the save screen without creating a new save if they would like to continue without saving. Flip a switch, autosaves disabled for that play through.
It's not 100% clear to me what you're planning, but say you have 8 save slots and you want to find the next available slot, I guess you could loop:

control variables X = 0
LOOP
control variables X += 1
IF X > 8
-> show text: "you don't have free save slots"
-> break loop
IF StorageManager.exists($gameVariables.value(X))
-> // do nothing
ELSE
-> break loop

And then your variable X gives you the next empty save slot.

Don't know how you'd do that 'multiple people playing their games stuff' without telling them to use specific slots. And yeah, there may be easier ways and/or plugins to do this. I just replied in this thread because I was confused about the other person saying that script not working, LOL.
It's not 100% clear to me what you're planning
Sorry, I think I made a mess of things by giving 2 examples that are exactly the same.

I think your system above will work fine, but to go ahead and clarify, I'll give more detail on the save system I would like to use for my game;

A lot of modern games utilize autosave systems, in fact, many games now don't even require the player to select the save option at all. It just creates a "profile" (In terms of RPG Maker, that would be our save file) and continually writes to that same profile. The main benefit of this system is that should the game crash or there is a power outage or the player hastily closes the game without much thought, it's not a big deal because the game aggressively autosaves constantly. Not much progress would be loss. The second benefit to this is that because the same save is constantly being updated, the ability to rewind time through "save scumming" is not possible.

While the system in my game I don't think will be as aggressive, I was thinking of having the game autosave on every map transfer and every time the player is defeated (there is no game over screen in my game). That way players don't have to worry about progress loss should something happen, and hopefully it will discourage save scumming and allow players to commit to their choices.

The autosave part: kind of not a problem because the script @dusk_13 wrote and shared already does that.

It is only the matter of the creating of the new save file that I am trying to solve. I just don't want, at the very start of a new game, for the game to accidentally overwrite an already existing save.

I hope that clarified things. Sorry about the confusion.
I think the most basic and easy way to solve this is, at the very beginning of the game, make an autorun event that immediately opens the save menu. Put a text message warning before or after opening the menu that lets the player know a save file must be made because otherwise slot 1 could be overwritten, and a confirmation prompt after the save menu in case the player accidentally hits a wrong button.
Something like this.

1693453306000.png
Yeah, I think what I wrote earlier would automate it. Or you can do it manually like dusk_13 said. But I checked it out and it seems that "DataManager.lastAccessedSavefileId();" doesn't always default to 1. If I started a new game, it seemed to give me a value of my highest save slot id used +1. Like if I had a save in slot 5 it would give 6 on new game (before saving).
Cool! I got it to work!...I think...
Here's what I did:
Starting with creating the new save (the most important part) I mostly followed your instructions. I'm ashamed to admit it too me a minute to understand what your event was doing (mostly the conditional with the script, the "do nothing" threw me off for a moment :LZSlol:) so I commented things to help me, hopefully these comments help others too!
Saving.png

There are 12 save slots available in my game, so it checks if any of those 12 are available, if not the player can chose to overwrite an existing save or continue without saving.

As for handling the actual autosave itself, nothing changed at all from what was discussed above, other than putting the autosave script into a conditional branch. If the autosave switch is off then it will not execute the autosave.

It seems to work fine! I'll play around with it a little bit more to make sure everything is working as intended and then mark the thread as solved.
Cool. Yeah the coders probably would just make it a script like 'if NOT', by putting an ! in front of the script, instead of using IF->do nothing, ELSE-> X.

Also, it's not clear to me what all those lines given in the script call list for save do, but if it's working for you with just that DataManager.saveGame(slotId);, then I guess it's fine.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-create-an-aggressive-autosaving-conditional-branch-to-check-saves.160744/