MZ Error "Cannot read propety 'pages' of undefined" when loading

Hello, I'm trying to make various custom image based menus ( just so that I can make them look more customized and pretty), but I've been running into a problem where if I try to continue/load a game from my custom title menu (located on a map, I'm using ZainWD title skip plugin), it gives me an error saying "Cannot read propety 'pages' of undefined". I tried some other ways of loading the game but they either give the same error or they just don't load anything, just goes back to the title menu and resets it.

(Btw when I put 2 events on a map that call the Save common event and Load common event, and save from one of them and load using the other, it works perfectly, loads everything as it should be as far as I can see it, I think this is an important bit of information that might narrow down where the problem is coming from. Also, when I push scene load, instead of calling my Load common event, and load the file I saved using my custom Save common event, it works as intended, so I'm guessing the problem is not with how the save event is set up.)

I'll attach some images that hopefully could help show more information.


This is how I save the game (this is inside the "!save menu" common event):
1000080194.png


This is how I'm trying to load the game (this is inside the "!Load menu" common event):
1000080193.png

[Translation: condition: SaveLoad_menu_cursor = 1]
This is how I call the Load common event inside the title menu event (event is set to parallel)
1000080195.png

[Translation: Condition: Title_menu_cursor = 2
Condition: Script: DataManager.isAnySavefileExists()
Wait 10 frames
Common event: !Load Menu ]

This is the error message:
1000080196.png


And this is the console thing:
1000080197.png


I'm sorry if I said anything wrong, English isn't my first language.

I'm very sad that I wasn't able to fix this even though I researched for alot of days, I couldn't fix the problem, thank you for anyone who decides to reply or try to help.
This is the MZ example for Load Game from the MV / MZ Script Call List:
Spoiler: script call list - load game - mz example
JavaScript:
// Continue from save 4; play success/fail SE; turn on switch 100
DataManager.loadGame(4)
  .then(() => {
    SoundManager.playLoad();
    SceneManager._scene.fadeOutAll();
    if ($gameSystem.versionId() !== $dataSystem.versionId) {
      const p = $gamePlayer;
      p.reserveTransfer($gameMap.mapId(), p.x, p.y, p.direction(), 0);
      p.requestMapReload();
    }
    SceneManager.goto(Scene_Map);
    $gameSystem.onAfterLoad();
  }).catch(() => {
    SoundManager.playBuzzer();
  }).finally(() => {
    $gameSwitches.setValue(100, true);
  });
$gameSystem.onAfterLoad() should be at the end of the then block. You have it at the start instead.

If that doesn't fix it...I've seen this error reported before, e.g.
I think it's something to do with the load process ending mid-frame, but I'm not certain. 😴

I've tried writing some plugin code to work around that problem:
Rough idea (untested):
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Adds a script call to load a game.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/170077/
 * @help In a Script command, you can use this:
 *          loadGame(slotId)
 *     e.g. loadGame(0)   - loads autosave
 *     e.g. loadGame(1)   - loads save ID 1
 * It should load synchronously, blocking updates until complete.
 *
 * Free to use and/or modify for any project, no credit required.
 */
;void (() => {
'use strict';
  let loadId = -1;
  let busy = false;
  globalThis.loadGame = function(slotId) { if (slotId >= 0) loadId = slotId; };
  const load = function() {
    if (loadId >= 0) {
      busy = true;
      DataManager.loadGame(loadId).then(() => {
        SoundManager.playLoad();
        $gamePlayer.reserveTransfer(
          $gameMap.mapId(),
          $gamePlayer.x,
          $gamePlayer.y,
          $gamePlayer.direction(),
          0  // fade black
        );
        if ($gameSystem.versionId() !== $dataSystem.versionId)
          $gamePlayer.requestMapReload();
        SceneManager.goto(Scene_Map);
        $gameSystem.onAfterLoad();
      }).catch(() => {
        SoundManager.playBuzzer();
      }).finally(() => {
        busy = false;
      });
      loadId = -1;
      return true;
    }
    return false;
  };

  // Patch - block scene updates while busy loading.
  void (alias => {
    SceneManager.updateMain = function() {
      if (!busy)
        alias.apply(this, arguments);
      load();
    };
  })(SceneManager.updateMain);

})();
Personally I got tired of trying to do this with script calls and did wrote a plugin for it: feature D21 of Cae_Tweaks ("synchronous save/load plugin commands"). Note that it uses essentially the same approach as the script call & event that I suggested here, so any problems with one will probably be present in both.
(The Cae_Tweaks version might be safer: in v15 I rewrote it to use a "request" type structure, so that the load process can't even start mid-frame.)

Someone else may have more ideas~
Let's start at the very end.

"Cannot read property 'pages' of undefined"

I haven't used MZ myself, but from VXA onward the only data object that has pages would be a map event - nothing else can have multiple pages.

So your error tells you that the engine tried to process an event that does not exist.
Likely because it was overwritten by the load process itself.

EDIT: Ninja'd
sorry, since caethyril explained it from the other side of the logic, I won't bother with writing the entire analysis, too short on time for double work
This is the MZ example for Load Game from the MV / MZ Script Call List:
Spoiler: script call list - load game - mz example
JavaScript:
// Continue from save 4; play success/fail SE; turn on switch 100
DataManager.loadGame(4)
  .then(() => {
    SoundManager.playLoad();
    SceneManager._scene.fadeOutAll();
    if ($gameSystem.versionId() !== $dataSystem.versionId) {
      const p = $gamePlayer;
      p.reserveTransfer($gameMap.mapId(), p.x, p.y, p.direction(), 0);
      p.requestMapReload();
    }
    SceneManager.goto(Scene_Map);
    $gameSystem.onAfterLoad();
  }).catch(() => {
    SoundManager.playBuzzer();
  }).finally(() => {
    $gameSwitches.setValue(100, true);
  });
$gameSystem.onAfterLoad() should be at the end of the then block. You have it at the start instead.

If that doesn't fix it...I've seen this error reported before, e.g.
I think it's something to do with the load process ending mid-frame, but I'm not certain. 😴

I've tried writing some plugin code to work around that problem:


(The Cae_Tweaks version might be safer: in v15 I rewrote it to use a "request" type structure, so that the load process can't even start mid-frame.)

Someone else may have more ideas~
Thank you so much for your reply! I saw the your message yesterday but only had time to test it today. I just came back home and I tried fixing the script I was using, using the plugin you attached here and using your tweaks plugin, I had similar results unfortunately.
1755813155233.png

this is the error message that appeared, I think its the same from before.

- I was able to load and save the game within the same map.
- Also when I teleported to another map (after saving on the previous none) and put the load event there and interacted with it, it loaded normally.
- Also one thing I never tried before which made me even more confused, I changed the place where the player starts to a random map, where the title menu event didnt exist, I then loaded the save file I saved on the previous test using the custom load menu (after closing the previous game) and it worked! it teleported me to the right map where I saved from last time.
- I tried changing the first place of where the player shows up on a new game to an empty map where it could then teleport me to the map with the title event, when I tried loading the game it didnt work.
(these above were made using the script command from your tweaks plugin)

I think these are some good extra information

I have no idea of what else I could do, I really wanted this custom menu to work.

EDIT: I kept testing the game doing the above steps over and over again to see if I could see something similar between these and as to why they were working.
but now I can't load a file that was saved if I do it from another map, I don't know why it was working before, and I don't know what I did that made it not work now.
When I try to load from a different map, it gives me this error now:
1755816799804.png

1755816868515.png

"Cannot read property "note" of null"

I also get this error now when I try to load from the title map using that uses the title event

I got a bigger error once where it said both "Cannot read property "note" of null" and "Cannot read property "pages" of undefined", but I can't seem to replicate the thing that triggered that to happen on the console.

​


Let's start at the very end.

"Cannot read property 'pages' of undefined"

I haven't used MZ myself, but from VXA onward the only data object that has pages would be a map event - nothing else can have multiple pages.

So your error tells you that the engine tried to process an event that does not exist.
Likely because it was overwritten by the load process itself.

EDIT: Ninja'd
sorry, since caethyril explained it from the other side of the logic, I won't bother with writing the entire analysis, too short on time for double work
thank you so much for your reply either way, I really appreciate it!
Based on what you've said, it does sound like it could be related to event counts. E.g.
  1. Save on map A, with 2 events.
  2. Go to map B, with 3 events.
  3. From map B, load the save made on map A (with fewer events).
  4. Game tries to update events 1~3?
  5. => Error! Can't update event 3 because it doesn't exist on map A.
Even if that is the case, though, at the moment I can't see why that kind of thing might happen. Maybe it's to do with the player transfer sequence or something... 😴

- I tried changing the first place of where the player shows up on a new game to an empty map where it could then teleport me to the map with the title event, when I tried loading the game it didnt work.
(these above were made using the script command from your tweaks plugin)
If this case is reproducible: does it happen if you try it with all (other) plugins turned off? I.e.
  • If using the script call to load: with no plugins enabled; or
  • If using a plugin to load: with only that plugin enabled.
Based on what you've said, it does sound like it could be related to event counts. E.g.
  1. Save on map A, with 2 events.
  2. Go to map B, with 3 events.
  3. From map B, load the save made on map A (with fewer events).
  4. Game tries to update events 1~3?
  5. => Error! Can't update event 3 because it doesn't exist on map A.
Even if that is the case, though, at the moment I can't see why that kind of thing might happen. Maybe it's to do with the player transfer sequence or something... 😴


If this case is reproducible: does it happen if you try it with all (other) plugins turned off? I.e.
  • If using the script call to load: with no plugins enabled; or
  • If using a plugin to load: with only that plugin enabled.
Hi! It's been a while, I just noticed I didn't respond to this post, but I did see it at the time.
I tried turning off all plugins and it still didn't work, but it's ok.
I talked to someone on reddit about how they made their custom picture based load menu work, and they gave me the same solution they used, which was modifying the scene_load so that when it gets called, it loads a file instantly without user input, and it loads the file number based on a variable, which would be the same variable used for the current selected cursor of the custom image based scene, like:
>Cursor variable is 3
>Call the Load menu
>The Load menu automatically loads file 3, since cursor variable is 3
(at least that's what I understood that happens lol)
I just wanted to say thank you for helping me, I really appreciate it!
I talked to someone on reddit about how they made their custom picture based load menu work, and they gave me the same solution they used, which was modifying the scene_load so that when it gets called, it loads a file instantly without user input
Yea, I've since updated Cae_Tweaks to v18, adding a "safe mode" to feature D21 (enabled by default). It works in a similar way to what you describe: the plugin's "load" command goes to a custom scene, which loads the requested save then returns to the map scene.

(I'm still not certain exactly what causes the error with the "not safe" approaches, but I'm pretty sure a complete scene change should prevent it. 😮‍💨)

Good to know you found a solution! 😂

Original thread: https://forums.rpgmakerweb.com/threads/error-cannot-read-propety-pages-of-undefined-when-loading.179679/