[RMMV] Error on Load: Cannot read property 'pages' of undefined

Hello Folks,


I’m working on a Game with a mouse-driven HUD inspired from Divinity/Baldur’s Gate, and I’m encountering issues around loading that I can’t seem to crack.

Fair warning, this my first serious game project, so please don’t have a heart attack if you see bad code or terrible practice with my eventing 😛


Background Info:

Here’s a shot of what the HUD looks like (WIP obviously – I’m using SumRndmDde’s HUD Maker for this):

Spoiler: HUD
BasicHUD.png

This is an entirely event-based menu system – so everything is happening on the Map Scene (equipment, item-management, etc.). Saving is handled by the following common event:

Spoiler: Save Event
Saving Event.png

The game also uses an event-based title screen (using SRD’s RemoveTitleScreen plugin). When a player loads a save file, the following event is called:

Spoiler: Load Event
Loading Event.png


The Issue:

When saving, then loading a file, things work fine as long as the player remains on the map they started the game in. When the player saves after changing maps (even if they return to the starting map), upon loading the following error happens:

Spoiler: Error
Error.png

Here is the Console Log of that Error:

Spoiler: Console Log
Console Log.png

I read up on similar errors, and I suspect it has something to do with plugin order and/or incompatibility. However, if that’s the case, I have no idea how I’m supposed to order them (besides the recommended order for Yanfly Plugins + keeping core plugins on top). I also could be wrong and it's something else entirely. Here’s my plugin list for reference:

Spoiler: Plugins
Plugins.png

Any insight on how/why this is happening? I’ve already been working on this project for a while, and due to the way it’s designed, using separate scenes for saving and loading is not an option for me, both aesthetically and gameplay-wise. Any help would be greatly appreciated.

Many Thanks,

Trasdill
1) which version is your rpg_core.js file? Please open it in a text editor and check the number in the title line.
2) does this happen if you start a new game instead of loading a savefiles first?
3) have you doublechecked the structure of your save?
I find it especially suspicious that you have offsets in the wrong order, that can easily destroy everything.
And why don't you use the default save methods?
Thanks for the quick reply. I'll answer as best I can:

1) rpg_core.js is v1.5.1

2) Not sure I understand the question - the game uses SRD's RemoveTitleScreen - so it is effectively starting a new game every time it is launched, in a designated "Title Map". From there, if the player clicks "Load Game", he is prompted to choose a save slot, and if a save file exists with that slot number, the game attempts to load it using the event listed above (when starting a new game, the player is simply transferred to the actual starting map)

3) Again, not sure how to check the structure of a save. Could you elaborate on this?

Can I ask what offsets are in the wrong order? As I said before, there's a lot I still don't understand about RMMV and I may easily be breaching best practice in many areas.

I don't use the default save method for the following reasons:
  • The game design I settle for only allows saving in the save slot you selected (similar to zelda games) - so I don't want players to be able to select a save slot upon saving.
  • I have not found a way to alter the save scene to make it fit with the game on an aesthetic level
  • I want players to be able to flit between menus in a single click (similar to Divinity/Baldur's gate) - pushing a new scene breaks that dynamic (i.e. you can't access the equip scene directly from the save scene or vice-versa; you va eto backtrack to the main menu first)

Hope this helps
2) a lot of plugins define their data when the original title screen "new game" is selected. Changing plugins often changes the savefiles structure. Loading an older save after any change in plugins has a good chance in creating similiar errors to the one you got, because the loading of the old data skips the definition of the data for the new plugins.

Even if you use a replacement title screen you have to have an option to create a new game including that new data sequence, or you (or your player) can get into a lot of bugs.
So you have to guarantee that this option is included somewhere, even if hidden (over write existing save while calling the new game sequence or something like that).

3) in your save event structure, you have a lot of offsets based on the value of variable 56.
However, there are ordered 303, 307, 311, 315, 332, 320, 324, 328.
The 332 is out of sequence, and all values are relative based on the content of 56 to make this even more problematic.
If something goes wrong in such a structure, the save command might have a different structure than the load command - and that could also result in such errors, for the same reason as with the first case: the (older) saved data structure is not the same as expected by the (never) load structure.
Thanks for the input, that makes more sense.

As a test, I disabled SRD's plugin, and let the "new game" button take me to my alternate title screen - new games created in that manner and then saved using my save event would load fine using the default "continue" button (regardless of what I set Variable 56 to), but not using my load event... so for now I can't get around loading from the title screen, I guess. I'll have to find another workaround.

Thanks again for the help
If that is the case, you might try it again after your development is complete.

As long as you change plugins, you'll need the regular new game command to allow for changes in the existing save data.
However after all plugins are finalized, a referrer in the replacement might work (depending on what plugins are installed) because after that there should be no changes in the data structure anymore.
You'll need to get your load event right for the final structure of course, so that is not automatically working...
Error analysis:
From reading the RMMV code referenced in your error messages, here's the best I could determine:
  • Whenever the map refreshes, it refreshes every event
  • To refresh the event, it figures out which event page is the active one (based on the event conditions) and displays that sprite
  • In your case, it is trying to refresh an event that doesn't exist (i.e. 'undefined')
  • The list of events on the Game_Map ($gameMap) doesn't seem to be in sync with the list of events in the loaded data for that map ($dataMap)
    • for example, if the $gameMap has a list of events ID #1-6 but the loaded data has events #1-5 then it would crash when trying to refresh event #6... because the data doesn't exist
    • This indicates a mismatch where one of these objects is not being created properly when the save file is loaded
Four suggestions:

1.) Something that looks to be missing from your events is how the player transfers from one map to another. Say the "Title" map is Map #1 and they last saved on Map #3. It's not clear to me how they are transferring from Map #1 to Map #3 when they select to load that file.

2.) I have created an evented quicksave/quickload system before, here are the script calls that I used. Your events currently have no error handling/backups, so there is a chance that data could get corrupted. These script calls include error handling/backups and also include transferring the player so possibly related to suggestion #1 (although in my game it only transfers within the same map).

Spoiler: Save Event Script Calls
Code:
$gameSystem.onBeforeSave();
if(DataManager.saveGame(1)) {
   StorageManager.cleanBackup(1);
}
//replace "1" with your save file ID

Spoiler: Load Event Script Calls
Code:
if(DataManager.loadGame(1)) {
   SoundManager.playLoad();
   this.fadeOutAll();
   $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
   $gamePlayer.requestMapReload();
   SceneManager.goto(Scene_Map);
   $gameSystem.onAfterLoad();
}
//replace "1" with your save file ID

3.) You have an unnecessary DataManager.saveSyncData() script call in your Save event. This function is already included by HIME in the DataManager.saveWithoutRescue() function.

4.) If none of that works, try testing without the HIME Save Sync plugin. I don't know if that plugin causes the issue directly but it complicates the bug-finding. See if you can get this save system to work first, then add that plugin to the mix.
Thanks a lot for the tip, Guvner! I played around your script and Bingo! the game was checking for events on the wrong map. After including
Code:
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
$gamePlayer.requestMapReload();
to my Load script, it's working well, regardless of which map I save in.

I'll also try your save event as it looks much cleaner than mine, and I'll keep in mind your suggestion regarding the SyncData function (I didn't know that was included in the saveWithoutRescue function - I guess I got a bit paranoid about this one because I use common variables a LOT via this plugin)

In keeping with Andar's recommendation for "new game" mechanics, I'm now using HIME_PreTitleEvents plugin rather than SRD_RemoveTitleScreen, as that allows me to launch a new game via the DataManager.setupNewGame() function. If I understood this right, that should avoid future problems when messing around with plugins.

Thanks a ton for both your help! I was really pulling my hair on this one.

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-error-on-load-cannot-read-property-pages-of-undefined.93505/