Quick Save / Load via plugin command

I'm looking for a plugin with the following feature:
-An option to save/load game to/from savestate1 using a plugin command.

Thanks to anyone willing to make this.
I wrote code for autosave / autoload here in the JS snippets thread, so that can be converted to a plugin command like this:

Code:
(function() {
    const Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function (command, args) {
        Game_Interpreter_pluginCommand.call(this, command, args);
        if (command.toLowerCase() === 'autosave') {
            let saveId = 1;
            if (args && args[0]) {
                saveId = parseInt(args[0]);
            }
            $gameSystem.onBeforeSave();
            if(DataManager.saveGame(saveId)) {
                StorageManager.cleanBackup(saveId);
            }
        }
        if (command.toLowerCase() === 'autoload') {
            let saveId = 1;
            if (args && args[0]) {
                saveId = parseInt(args[0]);
            }
            if(DataManager.loadGame(saveId)) {
                SoundManager.playLoad();
                SceneManager._scene.fadeOutAll();
                $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
                $gamePlayer.requestMapReload();
                SceneManager.goto(Scene_Map);
                $gameSystem.onAfterLoad();
            }
        }
    }
})();

You can now use a plugin command in the following formats (note it is not case sensitive, i.e. 'AuToSaVe' is the same as 'autosave' or 'Autosave')
Code:
autosave     // saves to slot 1
autosave 8  // save to slot 8
autoload    // loads from slot 1
autoload 8 // loads from slot 8
@Aloe Guvner Awesome, thanks. I'm at work right now, but will try it as soon as I get home.
@Aloe Guvner I've been getting this error: "Cannot read property 'pages' of undefined" upon autoloading a save state. After some testing different scenarios, I'm thinking it only occurs when autosaving and then autoloading within the same session, because when I autoload that same save state after a reset or restart of the game, it works just fine.
@Milennin Works fine when I test it on a blank project with no other plugins enabled.

So you probably know what my next questions are:
  • Can you post a screenshot of the full error message from the Console (press F8 during playtest to open the console)
  • Does this error occur on a blank project with no other plugins installed?
    • If no, turn on the other plugins one-by-one until it crashes, which will identify the incompatible plugin
@Aloe Guvner This is a screenshot with all plugins turned off:
Fvgkcu0.png

I can try in a blank project later, but short on time right now.
How about a blank map with only 2 events, one for autosave and one for autoload set to a trigger of Action Button. Does it work in this scenario?
How about a blank map with only 2 events, one for autosave and one for autoload set to a trigger of Action Button. Does it work in this scenario?
Yes.

It also works in my existing project in some scenarios, but can't find out when it breaks, after doing more testing. Like, I put the load command at the top of an event, it works. I put it below a few commands, it breaks. But then I put it back at the top, and it still breaks. I load the save once, it works. I load it again from the same event, it breaks.
I digged around and found a script call to auto load the game, which seems to give more consistent results. It only really seems to break if I transfer the player right as the game loads. Put in a wait 1 frame between it, and it works fine. The script call error, when it pops up, is pretty similar, except it says null, instead of undefined at the end.
Probably then due to some way how it initializes the map (and thus, initializes all the events on the map). The autosave/autoload script I proposed has the standard MV functions almost exactly how they are used in the save/title scenes. But loading from the title scene is probably simpler than loading directly from the map scene.

I'm not surprised actually that it crashes when trying to use autoload in the middle of an event. When an event is running, it has all the commands queued up in a list, and it works through that list. When trying to reload a map, that list might still be present in memory. The standard MV functions for load only happen normally from the title screen, so probably it never clears that queued list from the memory.

If you have a map where it consistently crashes, feel free to PM me the MapXXX.json file (from your data folder) of that map. Don't send any of the graphics, I'll just replace it with the RTP graphics. I'll run the debugger and try to see what's causing it.
Did you guys ever find out what was causing this?
Did you guys ever find out what was causing this?
Not exactly. Putting in a 1 frame wait seemed to make it work in more cases, but it still messed up in some scenarios. Getting to an auto-load event that worked was good enough, because when it works, it works consistently. When it fails, it fails consistently.

Original thread: https://forums.rpgmakerweb.com/threads/quick-save-load-via-plugin-command.105757/