MV Loading using a script call

I’d like to load the last saved game using a script call. I tried to use this:

DataManager.loadGame(DataManager.latestSavefileId());
SceneManager.goto(Scene_Map);

It loads the game, but before this, for a short moment, I get a screen with some wrong tiles. It doesn't happen when I load normally. What's wrong with this script call?
I'm not sure why you have the SceneManager call in there. Part of loading the game is taking you to the appropriate map afterward. If that function call is queued up and doing something, it could be causing your glitch.
I think SceneManager isn't necessary, you can try this script that I use.
Spoiler
JavaScript:
/*script can be found below. credit @ldd if you want, and tell me if you'd want an actual plugin for this
*/

Scene_Load.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
};

Scene_Load.prototype.start = function() {
Scene_MenuBase.prototype.start.call(this);
var id = DataManager.lastAccessedSavefileId();
DataManager.loadGame(id)? this.onLoadSuccess() : this.onLoadFailure();
};
This script skips the continue window slot and loads the last file. Hope it works!
A bit late to the party, but for sake of completion:

If you save/load your game directly through a script command, the game will save/load the game state in the middle of processing a frame, which is not supposed to happen by default and can cause issues in some cases.
(When saving, some of the process for that frame might be skipped/repeated after reloading; when loading, the game will finish processing the frame using and modifying a mix of old and new game data).

So using a plugin to ensure the loading is done outside the games update loop is recommended.
Thank you all very much! I found the plugin I needed.
Hi @Den_C , which plugin did you use?
Actually, I didn’t exactly mean that I found the plugin that loads the last saved file. I wanted to say that, thanks to the help of the great people on this thread, I found the solution for my specific situation.

If you’d like to use a script call (in an event), you can use the script posted by SuzuMito7u7 above. If you’d like to load the last save after Game Over, you can use this:

​

Hope it helps.

Original thread: https://forums.rpgmakerweb.com/threads/loading-using-a-script-call.134735/