How do I return to the most recent save state through a script? (custom game over screen)

I made my own custom game over screen with two options, one being "continue" and the other "exit". I want the "continue" option to take the player back to the last time that the game was saved. I see that you can open the save screen through an event command but I don't want this. I want it to be so that as soon as you hit continue it loads into the most recent save. Is there a way to do this through events or scripts or do I need a plugin?

This is what my event looks like right now.

EDIT: Just to be clear, this is for a custom game over screen.

EDIT #2: Title change to clarify

Screenshot (488).png
I found this thread which may be exactly what you're looking for.
I found this thread which may be exactly what you're looking for.
This plugin is great but unfortunately, it only works for the title screen and doesn't give me the option to do it through event commands/a script.
This plugin is great but unfortunately, it only works for the title screen and doesn't give me the option to do it through event commands/a script.
I've never messed with loads and saves, but wouldn't the script alone accomplish what you need through a script call?


Code:
var id =DataManager.lastAccessedSavefileId();
DataManager.loadGame(id)? this.onLoadSuccess() : this.onLoadFailure();
I've never messed with loads and saves, but wouldn't the script alone accomplish what you need through a script call?


Code:
var id =DataManager.lastAccessedSavefileId();
DataManager.loadGame(id)? this.onLoadSuccess() : this.onLoadFailure();
I tried it as a script call but it didn't work unfortunately.
Bump?
I tried it as a script call but it didn't work unfortunately.
Well it should work. I said it a lot already and I'll keep saying it: Just telling us something "didn't work" is not at all helpful in providing further help. Can you please be more specific? What exactly did you try (preferably with screenshots)? What exactly did you expect to happen? And what exactly happened instead? Can you try again while the console is open (F8) and post the output (if any) as a screenshot?
I checked the script call list out of curiosity and it gives this kind of code to load (I put the latest save file ID script to the save file ID spot). This at least seemed to load my save when I tested it...

if (DataManager.loadGame(DataManager.latestSavefileId())) { $gameSystem.onAfterLoad(); SceneManager._scene.fadeOutAll(); if ($gameSystem.versionId() !== $dataSystem.versionId) { var p = $gamePlayer; p.reserveTransfer($gameMap.mapId(), p.x, p.y, p.direction(), 0); p.requestMapReload(); } SceneManager.goto(Scene_Map); }
I checked the script call list out of curiosity and it gives this kind of code to load (I put the latest save file ID script to the save file ID spot). This at least seemed to load my save when I tested it...

if (DataManager.loadGame(DataManager.latestSavefileId())) { $gameSystem.onAfterLoad(); SceneManager._scene.fadeOutAll(); if ($gameSystem.versionId() !== $dataSystem.versionId) { var p = $gamePlayer; p.reserveTransfer($gameMap.mapId(), p.x, p.y, p.direction(), 0); p.requestMapReload(); } SceneManager.goto(Scene_Map); }
Thank you. This worked.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-return-to-the-most-recent-save-state-through-a-script-custom-game-over-screen.150512/