Need help with load script!

Hello! My game has only one save slot. I know how to save to specific save slot via scripts, but I couldn't find a way to load the slot I want via a script. I don't use any plugins. I tried to use this script:
Code:
if (DataManager.loadGame(1)) {
  $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);
}
but for some reason i get "Cannot read property 'pages' of undefined". Can someone help me please?
Have you tried searching for the error? This has come up before. I Googled "rpg maker load game pages undefined" and found:

(has a link to MV code)

Just reading through it, it looks like you've called onAfterLoad() too far up. You're doing that before sending the player to the map, so the events to check don't yet exist. Try moving it to the bottom as illustrated in the link above.

You can also see this in the default code - loading the map is done inside of onLoadSuccess(), and onAfterLoad() is called after that, when leaving the load game scene.

As a tip, when you're posting code you want to use the CODE tags (the </> in the edit bar). That will preserve your indentation and not eat brackets.
Oh, okay! Thank you for help!
Oh, okay! Thank you for help!
I'm trying to do the exact same thing. Do you mind sharing your script that worked for you?
I'm trying to do the exact same thing. Do you mind sharing your script that worked for you?
Yes, of course!

Code:
if (DataManager.loadGame(1)) {
    $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    $gamePlayer.requestMapReload();
    SceneManager.goto(Scene_Map);
    $gameSystem.onAfterLoad();
}
Yes, of course!

Code:
if (DataManager.loadGame(1)) {
    $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    $gamePlayer.requestMapReload();
    SceneManager.goto(Scene_Map);
    $gameSystem.onAfterLoad();
}
Thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-load-script.160532/