Lihinel

Veteran
Veteran
Joined
Nov 9, 2013
Messages
271
Reaction score
339
First Language
German
Primarily Uses
While looking for ways to add my own data to the save file, I noticed, that there is a character limit to save files:
Code:
DataManager.saveGameWithoutRescue = function(savefileId) {
    var json = JsonEx.stringify(this.makeSaveContents());
    if (json.length >= 200000) {
        console.warn('Save data too big!');
    }
    StorageManager.save(savefileId, json);
    this._lastAccessedId = savefileId;
    var globalInfo = this.loadGlobalInfo() || [];
    globalInfo[savefileId] = this.makeSavefileInfo();
    this.saveGlobalInfo(globalInfo);
    return true;
};
After some web searching I only found a few topics on this, one mentioned that this 200000 limit is because of parser issues when files get longer than that. One topic also mentioned reaching this limit on a 101x100 or so map with 100 events.

I don't plan to have that many events on a map, but it made me a bit nervous about just putting my own save data into the regular file.

What I do might have are files that look like this in json:
Code:
[
[ {"x":100,"y":100,"waiting":12000,"busy":120}, {"x":120,"y":120,"waiting":7000,"busy":110} ],
[ {"x":12,"y":200,"waiting":14000,"busy":170} ]
]

They store the minimum amount of information I need if I want to recreate the Townbuilding I have in VXAce in MV.
So a single building is about {"x":100,"y":100,"waiting":12000,"busy":120} which is length 44. Lets be a bit generous and assume 20 buildings for each town and 10 towns each in 7 regions, we are already at ~ 62000 charcters not counting , and [].

From what I have read in the past 2 Threads there are probably 2 ways to save, one for desktop and one for all deployment.

So should I try and create my own save files in addition to the default ones to store that data and edit the DataManager functions based on the existing DataManager functions, or is there again a better way, thats just wasn't picked because it didn't exist in the old version of JS that was used when MV was created?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,147
Reaction score
10,708
First Language
Czech
Primarily Uses
RMMV
The reason 200000 is the limit is because some browsers' JSON parsers use memory buffers of this size (or at least they used to in past). I haven't had any problems on Chromium based browsers with larger files, but I did not try to push my luck to what's the max size they can parse without an issue. MV still needs to carry this warning to ensure as much compatibility with various browsers as possible anyway.
Nevertheless, there are always solutions. In fact this problem in particular can be solved simply by separating the file into multiple smaller ones and loading them individually if needed.
So it's not whether you should or should not, it's whether you need or need not. And I assume you can answer this question yourself, since who knows better the length of savefiles in your game than you?
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,143
First Language
English
Primarily Uses
RMMV
Eh, it's just a warning and 200 000 byte limit is arbitrary. I would not worry about it.

For theoretical purposes, the maximum length of a string in JS is roughly 1GB which is 10 000x larger (4 orders of magnitude larger) than that "limit". Of course I would not recommend something so big because it would require a large amount of RAM.

If you want to see the maximum length of a string, it depends on the environment, but you could test it with something like:
Code:
var str = 'a';
while (true) {
    str += str;
    console.log(str.length);
}
For me it crashed somewhere more than 500MB
 

Lihinel

Veteran
Veteran
Joined
Nov 9, 2013
Messages
271
Reaction score
339
First Language
German
Primarily Uses
Thanks to both of you.
I'll just go with adding new save data to the regular file for now, if I encounter any problems I can change it later on.
 

Latest Threads

Latest Profile Posts

Who wants to see my review of the worst star wars movie? This movie has all the excitement of being on Jury Duty of the most boring case ever about trade negotiations.
A lot to learn to make a game. Can I handle it?
I've been working on status effects since last thursday, and today I finished the core mechanic of Zombie, Teleport, Curse and Recall. Zombie and Curse are lacking a few things to make them complete atm. Teleport though is the "HAHA" spell for some of my mobs, but can "NOPE" at them with Recall.
I'm weird as there are a few game franchises I'll watch and read about, but have no interest in playing.
Humans have such a capacity to assign personalities and love to objects. We do this because we love them. It's interesting then that our fears over AI are that they won't love us back and will instead hate us.

Forum statistics

Threads
115,158
Messages
1,087,723
Members
149,702
Latest member
Hidemitsu
Top