RMMV [Solved maybe] How do I define custom objects in save files?

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Data is serialized in JSON when it's saved.

When you save the $gameActors, and then you load them from the save file, they are still Game_Actor objects.

However, for my custom objects such as grid data, etc, they just get turned into Object and lose all the functions and stuff.

So it crashes when it tries to access it like a specific instance of a class, because it lost all that information when it was serialized.

Example: Game_Map has an array of Game_Vehicle objects stored as $gameMap._vehicles. When the map is saved and loaded, they're still Game_Vehicle objects.

1598495469240.png

Whereas for me, my objects get wiped out

1598495595094.png
 
Last edited:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
Your object class must have a name.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
Don't know if I really get it.
But if you want to store custom data in the save file, you can't create your classes normally with es6 syntax.
You have to do the way it is in the core files:

JavaScript:
function Game_Actor() {
    this.initialize(...arguments);
}
Game_Actor.prototype = Object.create(Game_Battler.prototype);
Game_Actor.prototype.constructor = Game_Actor;
I don't know, maybe there is a way to use es6 class and save it.
But I think the real problem is in the JsonEx class.

I have managed to do it, but with a lot of turn around that make my code ugly and not very readable.

I mean, assuming that I understand what you are talking about ^^'''
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Your object class must have a name.
What does it mean to give an object class a name lol

Don't know if I really get it.
But if you want to store custom data in the save file, you can't create your classes normally with es6 syntax.
You have to do the way it is in the core files:

JavaScript:
function Game_Actor() {
    this.initialize(...arguments);
}
Game_Actor.prototype = Object.create(Game_Battler.prototype);
Game_Actor.prototype.constructor = Game_Actor;
I don't know, maybe there is a way to use es6 class and save it.
But I think the real problem is in the JsonEx class.

I have managed to do it, but with a lot of turn around that make my code ugly and not very readable.

I mean, assuming that I understand what you are talking about ^^'''
Hmm, I did use the class syntax.
I was planning to rewrite it using the prototype way due to the aliasing issues that were brought up before. Maybe it's a good time to rewrite...
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
What does it mean to give an object class a name lol
I assumed you were still using prototype, then just having the class definition with a function name will work:
Code:
function MyClassName() {
}
For ES2015, they intentionally prevented people from doing that with the new class syntax, so you need to instantiate a new object yourself and then assign the data to it with Object.assign.

I would recommend using Object.assign even if you're going to use ES5 as its a safer method.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,090
Members
137,586
Latest member
Usagiis
Top