RMMZ Issue loading a game that has a new type of object

ze1

Regular
Regular
Joined
Apr 19, 2012
Messages
38
Reaction score
6
Primarily Uses
So I developed a rune system for my game where each rune is an instance of the object Game_Rune. I store all runes in an array inside Game_Party, like this:

JavaScript:
ZNT.Game_Party_initialize = Game_Party.prototype.initialize
Game_Party.prototype.initialize = function() {
    ZNT.Game_Party_initialize.call(this);
    this._runes = []
}

Game_Party.prototype.addRune = function(runeId) {
    if (this.hasRune(runeId))
        return 0;
    this._runes.push( new Game_Rune(runeId) );
}


When I save my game, this is how my Game_Rune object looks like. By this point, everything works fine, I can call any methods from my Game_Rune object and it all runs perfectly.

JavaScript:
Game_Rune {_runeId: 1, level: 1, _skills: Array(1), experience: 0}


However, after loading my saved game, this is how my Game_Rune object looks like. From this point on, nothing works. I can't call any of the Game_Rune methods anymore, because I get a "not a method" exception... It looks like the object loaded isn't a Game_Rune, but something else, like a generic object.

JavaScript:
{_runeId: 1, level: 1, _skills: Array(1), experience: 0, @: "Game_Rune"}

Is there any way to fix this problem? I have no idea what's happening :(
 

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,244
Reaction score
1,933
First Language
English
Primarily Uses
RMMZ
You didn't really show us any of the relevant code (such as the definition of the Game_Rune class and the methods that you're talking about, or the code that is specifically triggering the error), so it's kinda hard to tell you exactly what's happening. If you don't actually show us the code, then there's not much we can do to help you debug it.

If I were to take a stab in the dark, based on your description of the issue, it sounds like you're maybe trying to attach methods to the individual objects, instead of to the class itself. Methods don't get preserved when an object is serialized into JSON, so any methods that you've directly attached to the objects won't persist through game saves.

*edit* caethyril's explanation makes more sense.
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,261
Reaction score
4,738
First Language
EN
Primarily Uses
RMMZ
MV/MZ include specific encode/decode methods for preserving custom prototypes (Game_Actor, Game_Item, etc) through saves.

Make sure Game_Rune is declared as a global; if not, JsonEx._decode (rmmz_core.js) will not correctly reassign the prototype on parse.
 

ze1

Regular
Regular
Joined
Apr 19, 2012
Messages
38
Reaction score
6
Primarily Uses
Make sure Game_Rune is declared as a global; if not, JsonEx._decode (rmmz_core.js) will not correctly reassign the prototype on parse.
Yeah! Doing this solved my problem! I had the following code stored in a function, but when I put it outside the function, saving and loading objects of this type started to work! Thank you so much! :D

JavaScript:
function Game_Rune() {
    this.initialize(...arguments);
}
 

Latest Threads

Latest Posts

Latest Profile Posts

Me watching the game awards.

Gonzo, shut the **** up and show use some Elden Ring DLC. tumblr_422af97288e81470bb4ea56cce38e220_331927d8_500.gif
THE GAME AWARDS AHHHHHH!!!!!
I kept saying I suck at writing stories. But I can't believe I wrote one these days. Feels good now that the winged blonde girl I often share has an actual lore and plot going.
Huge breakthrough! I finally fixed the dimensions on the WEBM used in the cinematic that ends the demo and introductory segment in MC:RIS, around the one-minute mark:



(There's some audio desync because the capture is an MP4.)
Kudos to everyone making game jam games, because this month has been hell for my development time. I have made a cutscene, 2 sprites, and 1 tile.

I guess I've made conceptual progress in hammering out combat roles and having fixes to be implemented (though I haven't done that yet)

Forum statistics

Threads
136,822
Messages
1,270,417
Members
180,584
Latest member
LalaTheGhost
Top