[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');
console.log(JSON.stringify(MyMod.ds));
if(MyMod.ds.settings.opts === undefined) {
	console.log('Saving settings');
	MyMod.ds.settings.opts = MyMod.options;
} else {
	console.log('Settings found');
	console.log(MyMod.ds.settings.opts);
}

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.

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;      
        
        DataStore.saveSettings();
    };      

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.

Cheers

1 Like

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 ;)).

2 Likes