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

ze1

Veteran
Veteran
Joined
Apr 19, 2012
Messages
34
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

Veteran
Veteran
Joined
Jun 25, 2021
Messages
951
Reaction score
1,262
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
4,639
Reaction score
3,770
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

Veteran
Veteran
Joined
Apr 19, 2012
Messages
34
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 Profile Posts

imgur sure is getting weird, one day I lose gradually all my images, the other I get them back randomly and then again they disappear again.
Despite OPT2 praise it still has some strange stories in it. Lady Mikka is trying to work herself to death because of guilt. Guilt over what? ¯\_(ツ)_/¯ So instead of finding a NPC to have a heart to heart with her they decide the cure is a new kimono. So when she drops dead she'll at least be well dressed. I haven't even got to the strange part yet.
Did so much work on the game today. I wish I could post it all in this status update but there is a character limit of course haha. I thought about making a topic for updates, though... maybe.
The most recent sign that I am old. I have done martial arts for over 4 decades. Never HAD to stretch out. Good, of course, but never required. Was doing some kicks in the kitchen because, why not, and I felt a pop in the back of my thigh. Now I am limping around. Gotta love getting old.
One of the biggest perks of being fluent in English is how many new and interesting recipes I am able to find and try out that I would have hardly come across if I just spoke my mothertounge :3

Forum statistics

Threads
131,682
Messages
1,222,221
Members
173,435
Latest member
TheAmplifier
Top