MZ How to insert a custom save file information

Just a random question, are there any people here who play warframe? i have an entirely good reason for asking.
To answer the question, yes are people who play.
It is just not me.

Now tell us the reason (and why it is in a "Learning Javascript" forum)
Well the reason is I'm willing to offer something warframe players may want for something in return.
i know there are people who'd do it out of the kindness of their heart. but try to understand this one problem has been holding me back in my project for a while and when i thought i understood and solved it i ended up with.. bugs. long story short. I'm willing to offer a large amount ingame currency for anyone who'd you know assist me with solving this issue.

ok I'm in need of a way to save anything, any type of variables int, Boolean, array, object anything but i need to be able the access the data before any save file is loaded. its an annoying problem and my usual methods doesn't seem to be working. at this point I'm desperate as I've wasted yet another day trying to figure it out through numerous attempts all ending in failure in one way or another. id just like to see how someone would approach this problem as its frustrating and my own attempts seem to be getting nowhere. as for why this post is here, i plan to dissect whatever answer/s I get.... for me it is a learning experience and ill post my findings, notes etc. Surely I'm not the only one with this prob.

ps. i may come off as arrogant but I'm not, I'm just horribly frustrated.
Let me guess, you want to load data at the start of the game (i.e, title screen or something) before accessing the load menu? Then you want to make it global data that is shared across all of the saved games?
hmm you're half right the saved data will be for a save/load menu that has info about each file giving the user the ability to actually see what it is they are loading before actually doing so, if i could save like a number like on the first file, its = to say 3 id load info for that lvl etc. and if im able to do that something like

in

file 1 (that variable is 2) info for 2 is loaded

file 2 (that variable is 6) info for 6 is loaded

file 3 (that variable is 1000 ) info for 1000 is loaded

should be possible.

I kinda get how to save global data but its always undefined before the/a file is loaded and nothing i do seems to fix that. Like I tried loading the save files in an attempt to extract the info before actually loading the game, this works but produces so many bugs in return.
Ah yes, save file header (that was the name in VXAce)
In MZ, it is named as save file info.

Here is the piece of code that does it
Code:
DataManager.makeSavefileInfo = function() {
    const info = {};
    info.title = $dataSystem.gameTitle;
    info.characters = $gameParty.charactersForSavefile();
    info.faces = $gameParty.facesForSavefile();
    info.playtime = $gameSystem.playtimeText();
    info.timestamp = Date.now();
    return info;
};
As you can see, in the default save menu, you have a playtime, faces, etc.
Now you want to display a certain variable name, just add a new variable on there.
-sigh- thanks but ive already tried this tho. Thank you for your assistance youve helped even when you didnt have to.
-sigh- thanks but ive already tried this tho. Thank you for your assistance youve helped even when you didnt have to.
I don't like this response.
if you have already tried, show how you do it so we can see what is wrong with it. Not just a mere "I have already tried this" and said nothing more.

I won't ask for an in-game currency as compensation, as it also for my learning MZ code (it is also for my own benefit as well). But If you have already given up, then I'm also giving up.
ok, but be warned my coding is like the matrix you may not be able to understand it.

well my latest attempt went like this.

DataManager.makeSavefileInfo = function() {
const info = {};
info.title = $dataSystem.gameTitle;
info.characters = $gameParty.charactersForSavefile();
info.faces = $gameParty.facesForSavefile();
info.playtime = $gameSystem.playtimeText();
info.timestamp = Date.now();
info.savedatainfo__ = $gameSDtitle;
return info;
};

var cgos = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
cgos.call(this);
$gameSDtitle = new Game_SDTdata();
};

var msc = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
msc.call(this);
// A save data does not contain $gameTemp, $gameMessage, and $gameTroop.
const contents = {};
contents.sDTD = $gameSDtitle;
return contents;
};

var esc = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
esc.call(this);
$gameSDtitle = contents.sDTD;

};

//-----------------------------------------------------------------------------
// Game_SDTdata
//
// The thing.
function Game_SDTdata() {
this.initialize(...arguments);
}

Game_SDTdata.prototype.initialize = function() {
this._data = 0;
};

basically adding stuff necessary to save and load you understand.
it works but needless to say it only works after actually loading a file and then when i do that or attempt to i can only extract the data i need from the first file loaded. looping through and loading then extracting then repeating for the amount of files remaining doesn't work.

no amount of forced loading seems to by bypass that error. if there was a way to load and then unload the files, maybe then but... no progress. and its been over a week... I've never been stuck on a single prob this long before. I'm pulling at my hair.
Your make save file info is already correct.
But I notice other problems.

First of all though, instead of using a custom object, why not hardcode it to test things out?
For example
Code:
DataManager.makeSavefileInfo = function() {
    const info = {};
    info.title = $dataSystem.gameTitle;
    info.characters = $gameParty.charactersForSavefile();
    info.faces = $gameParty.facesForSavefile();
    info.playtime = $gameSystem.playtimeText();
    info.timestamp = Date.now();
    info.customData = 999;
    return info;
};
This is the only code you need.
Test it, if 999 is saved in the header.

Or if you want a little bit more dynamic
Code:
DataManager.makeSavefileInfo = function() {
    const info = {};
    info.title = $dataSystem.gameTitle;
    info.characters = $gameParty.charactersForSavefile();
    info.faces = $gameParty.facesForSavefile();
    info.playtime = $gameSystem.playtimeText();
    info.timestamp = Date.now();
    info.customData = $gameVariables.value(10);
    return info;
};
This will save the value of variable 10 as a save header/info (I prefer to call it save header)

Now, what part that got you wrong?
Here
var msc = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
msc.call(this);
// A save data does not contain $gameTemp, $gameMessage, and $gameTroop.
const contents = {};
contents.sDTD = $gameSDtitle;
return contents;
};
This part
Code:
const contents = {};
contents.sDTD = $gameSDtitle;
return contents;
You're returning an empty object as save content with your own data.
This mean, all save content is ignored
Afterall, what you do is
- Create object = {}
- Add your owndata = {}
- Return contents << this means that's all the save contents

What you should do is ...
Code:
var msc = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
  let contents = msc.call(this);
  contents.sDTD = $gameSDtitle;
  return contents;
};
wow.... I feel dumb, ill make the necessary adjustments and keep you updated.

update.
your first suggestion seems to work however I think I'm accessing the data incorrectly?
after loading a file, say file 1, I use the console to change the variable then save it however the returned variable doesn't appear to change back at the title screen or save load screen prior to actually loading the file.

I use the following.

DataManager.makeSavefileInfo().customData for checking to see if the data has changed as well as changing the value of the data.

ive also fixed the incorrect code.
How did you modify the makeSavefileInfo function?
Are you using a variable as I do?
yup I'm doing it just like you did, it returned 999. The only difference is that at runtime to edit that value I'm accessing it through the console. when I restart the game however the value returns to 999.
its entirely possible that I'm overlooking something very simple as I'm very tired. I've been at it for a day and with no real progress and I have work in a bit. I think ill turn in for now and continue tomorrow. also if you do play warframe i really wouldn't mind giving you platinum for your help.
Please post your code and how you change it by the console command.
Without those contexts, we don't know what is wrong.

Again, I don't play Warframe.
But you can do a favor for the whole forum by changing the thread title into something more clear like "How to insert a custom save file information".
Ok i tried doing this yesterday but the forum was down, anyway i rewrote the code without the fancy stuff so its not dependent on any resource files etc. It runs, anyway i tried doing the same thing i did with play time but it only returns the customData's original data which in this case is 777. no attempts to change it directly or indirectly have been successful. ill attach the new script as im not sure how to use code tags or spoiler tags.

but anyway.

As for the method, of updating customData i used (((DataManager.makeSavefileInfo().customData))) after loading a file, then by pressing f8 to open console i paste (((DataManager.makeSavefileInfo().customData = the data i want to test with))) before saving, i do this with all the files so theres no way it should return the original, but it does.

maybe youre seeing what im doing wrong?

Original thread: https://forums.rpgmakerweb.com/threads/how-to-insert-a-custom-save-file-information.132895/