[QUE] Am I using DataStore settings wrong or is it broken?


I’m trying to persist some mod specific settings for my mod. In a method called from my ready method I have the following code to set up reasonable defaults if its the first time the mod is loaded:

MyMod.ds = GDT.getDataStore('MyMod');
console.log('Load detected');
if(MyMod.ds.settings.opts === undefined) {
	console.log('Saving settings');
	MyMod.ds.settings.opts = MyMod.options;
} else {
	console.log('Settings found');

Then later on I have the following code called when the user changes an option:

MyMod.ds.settings.opts = opts

The option is there and can be read elsewhere - until I quit the game and open it again. Then when I try to get the data store again, it’s blank. I was under the impression that GDT just handles persisting the settings itself. Is there more that needs to be done?

If I change settings to data, move the first set of code to an event handler for the game loading, and manually save the game before quitting, then I can get data to persist between game launches, but I’d rather have this data available across all save files.

[QUES] [SOLVED] (GDT-ModAPI) Persistent Data

I think there is a bug where settings are not saved unless a game is saved. We will look into it.


@PatrickKlug Does this bug still exist? I am asking because I tried to get around the problem of .settings persistence using the following approach, but did not succeed :frowning:

    // Save settings to storage   
    this.save = function() {
        instance.store.settings  = tweakMod.settings;  
        instance.store.data      = instance.store.settings;      

Is there a way to persist .settings data using a workaround or something else? Or did I miss something?
Btw. saving the game using the mentioned approach was also unsuccessful.



I am also finding that anything in “data” does not get nullified if someone starts a new game whilst already playing a game.
So any flag I set in the first game are carried over into the next game, which is very annoying.


Looking at the source (https://github.com/greenheartgames/gdt-modAPI/blob/master/api/persistence.js) it seems I forgot the ‘new game’ situation. How embarrassing. I will fix this and finally add the event for ‘new game’ as well.

The workaround seems fine to me. Will have to investigate why it isn’t saving.

Thanks for reporting this and sorry for the late reply (have been on my honeymoon ;)).

[WIP] Camelot Expansion Pack -