GDT.getDataStore Doesn't Work


#1

I’ve tried using GDT.getDataStore and all that; I’ve looked at other forum posts, but GDT.getDataStore clearly is broken.

At this point I am beginning to believe that the only way to do it is through what @kristof1104 did in the competitor mod.


#2

I’m not aware of any issues with getDataStore. If you have a simple example that demonstrates the problem, I can take a look at it. The getDataStore support feature is implemented in the gdt-mod API itself so you should be able to debug it too, if you wish.

The code is here:

The documentation for it is here:


#3

Well, save-specific data doesn’t seem to work. A flag that equals true in one save should be false in another save; however, what happens is a flag that is set to be true is equal to true in every save, not just the one it was set to true in.

Hopefully that makes sense, haha.

.data is said to allow for “save-specific” data, but I have yet to be able to save data in a mod that isn’t present in every save.


#4

You can see how in GDT.eventKeys.saves.loading the data field is set to a new value from the save.

If you always see the same values, then I assume you might be acessing the old object from a previous load call instead of the new one.


#5

So what I mean is that if you assign the result of GDT.getDataStore().data to a global variable then this will not work correctly but if you access the .data property through the object that GDT.getDataStore() returns it should work.

To test just call GDT.getDataStore() anew whenever you use it and it should work fine.


#6

But is there a way to save/load a save-specific array?

I guess I could always set a bunch of flags for each item in the array, but it would me much easier if I could just save the array to a specific save.

I know there is a way, cause the game itself saves/loads arrays. For example, the mods being used in a saved game (GameManager.company.mods) is an array that is save-specific.

There are many other save-specfic arrays (i.e. GameManager.company.availablePlatforms, GameManager.company.gameLog, and so on)

So how do I go about saving my own array to a specific save?


#7

Arrays are no different from flags in this case.

Simply set the value via

GDT.getDataStore(pluginId).data["myArray"]=arr; 

to save it.

And get it via

var arr = GDT.getDataStore(pluginId).data["myArray"];

to access it whenever you need.


#8

Thanks a million! It works great :thumbsup: