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,851
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,557
Reaction score
3,752
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,775
Reaction score
1,197
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,851
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,557
Reaction score
3,752
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

While we prepare the official trailer, enjoy this kind-of-second teaser! ^^
-Ele
New Episodes of RPG Shenanigans Uploaded to Youtube!

Episode 5 - Surprise Party!
Youtube Link:
Episode 6 - Killer Gin
Youtube Link:
Episode 7 - Gaia's Melody: Echoed Melodies
(Coming soon!)

Episode 8 - Clarent Saga: Tactics
(Coming soon!)

Episode 9 - Star Shift
(Coming soon!)
When the Map Generator throws in the assets in the most dumbest way possible - your path is blocked :D

I went to sleep at 3 am because of my anxiety. Set up my alarm for 7 am so that I could have sasagues for breakfast and do morning routine before lessons starts at 8 am. I knew I wouldn't be able to sleep even after my lessons finished because I have to visit my grandparents today I was sad bc I was really tired. Thats when I realised. My lesson starts at 9 am. I could get one extra hour of sleep if I didnt forget it

Forum statistics

Threads
107,563
Messages
1,030,574
Members
139,671
Latest member
WDRS
Top