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,544
Reaction score
3,714
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,692
Reaction score
1,105
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,544
Reaction score
3,714
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 Profile Posts

My dynamic weather system grows... now with cloud cover influenced by wind speed! (4x playback) (Not final cloud image/map)
Wrote a plugin today that allows you to assign BGM, Battlebacks, and even Battle Entry SE's on a per-troop basis. Introducing a random encounter with a high-pitched Chicken Squeal is worth it all by itself.
Stream will be live shortly with some game development! Feel free to drop by!
Asphodelethe wrote on skybluehair's profile.
Hi! I loe your desert NPCs for adding some variety. I've used them in a free game (The Snow Elf on Itch.io) and I'd love to use them in the new game I'm working on, which I hope to release commercially. I'd love your permission if I could have it!


So I figured out how to put words and pictures in the screen transition. It even wipes away from both the top and bottom. The possibilities are endless! :LZSexcite: I'm going to devise secret messages now for them because I'm a terrible wonderful person like that. :kaopride:

Forum statistics

Threads
105,763
Messages
1,016,245
Members
137,450
Latest member
patriciabrown
Top