[SOLVED] DataStore data as array possible?

Hi there,

So I’m trying to create an array which is save specific, which I’m doing by using GDT.DataStore.data. However, it doesn’t seem as if it’s possible to use this object for arrays, though that might be because of my lack of knowledge and experience with arrays. I’ve uploaded my code to pastebin, which should probably make it easier to read rather than pasting it on here. From what I can see, this piece of code should be running without any problems. However, it isn’t.

I’d like to know whether or not it’s possible to use GDT.getDataStore.data as an array (and if not, if there’s a possible workaround for what I’m trying to do) or if I’m doing something completely wrong.

Hi,
I’ve never worked with GDT.DataStore, but if it doesn’t save objects, you should try this:

Serialize you array or object

var convertedObject = JSON.serialize(jsonObject);

This function converts object to string, so now you can save it.

Get object back

jsonObject = JSON.parse(covertedObject);

This function create array or object from JSON string.


NOTE: You cannot serialize or parse array if there is function inside array.

GDT.getDataStore("myMod").data.mySaveData = "biscuits"; does save the data in the save game, @janch32.

@Pastract, you forgot to add your mod ID parameter to the function, so the game knows where to save this :smiley:

So what you’re saying is I should add my mod ID (which is FSMPASTRACT) as a parameter to function a, making it

var  a = function (FSMPASTRACT) {
   // code
}

I’m slightly confused at how this would work.

Here’s documentation for dataStorage:

so if your mod ID is FSMPASTRACT, then you save data with this function:
GDT.getDataStore("FSMPASTRACT").data.myValue = "Hello!";

Or if the value is game-wide (save independent) then you can use:
GDT.getDataStore("FSMPASTRACT").settings.myValue = "Hello!";

(.myValue is your own variable name)

Yes, I know this, and this is exactly what I have done, is it not? I appreciate you two helping me, but I’m afraid I don’t quite understand what you two are trying to say.

You should also make GDT.getDataStore("FMPASTRACT").data into a variable so its a bit quicker :slight_smile: Have you created the array before you push to it? Doesn’t seem like it.

On the first line,

GDT.getDataStore("FSMPASTRACT").data.YPA = [];

This should create the array if I’m not mistaken?

I’ve updated the pastebin in the original post in which I’ve made it a variable and added comments to show what I’m trying to do.

Spotted it; Line 9.

&& GDT.getDataStore(“FSMPASTRACT”).data.YP > 0) {

This should be YP as YP is the difference between the last item in the array and the item before the last. What I’m in theory doing (well, trying to do) is:

var d = GDT.getDataStore("FSMPASTRACT").data
d.YPA = [0, 4, 5, 9]
d.YP = 9 - 5

NVM! Forgot to update tab, dont mind me.

Now, I’ll just look at a few things;

Line 1: Missing semicolon
Line 12: I don’t know exactly how it is, but I didn’t think you could just do “- calculation * 9” without having it predefined as a variable. Thats throws runtime exception in C++/C, Java and C#.

I’ve made it to where it should calculate 20% of YP before subtracting it, however this doesn’t change a thing as I’m still getting ‘GDT event handler error’ on M1 W1. When I try to get it to show me the value of YPA[0] and YPA[1] it doesn’t show anything too, so I’m still convinced it has something to do with the array.

Try to remove the array and just have values like “ypaMoney” instead. Messy, I know :smiley: Btw, you should try using an object instead of array. Works better.

1 Like

The thing about using the array is that I can (well, in theory I should be able to) add a value to it and subtract it with the previous value. By making two or more objects to calculate the yearly profit, I don’t see how I would be able to calculate the profit of year 2 after calculating the profit of year 1, whilst keeping the same value of the amount of cash the company had at the end of year 1, at the end of year 2, if that makes any sense.

EDIT: Nevermind, I’ve figured out an alternative way of doing it, and it worked when I tested it. Thank you both for giving up your time to help me.

1 Like

We can totally rule out the posibility of just building relations to get you into Nanonical . . . jk

1 Like

I do recall me saying that my programming knowledge was significantly less than yours/janch’s, and this is a perfect example :wink:

You underestimate yourself a lot. This is great work, and we would happily accept you into the bunch! We really hope to see you join us :slight_smile:

1 Like