question

squigglyo avatar image
squigglyo asked

Best way to save/store data?

Im trying to figure out the best way to save/store my games data.

I have around 100 bits of data I need to save.

Currently every 10 seconds, I save the game. Any changes made, are added to a string/string dictionary and only those ones are pushed to the cloud. So only the specific data that changes is being saved every x seconds.

Currently, im merging similair datas together (so it reduces the number of keys, but means that data that isnt changed gets saved due to the concatenation).

EG: There are 5 characters, each with 3 stats, so im storing those as a string that I pull apart in the client, and when I go to save, I put it into this string before sending back to the cloud

"1;2;3;1;3;2;1;3;2;1;3;0;0;0;0"

so thats 1 key in the database which I essentially turn into 15 in the client.

But if only player 1's power is updated, all 14 other stats are saved as well (29 chars are saved unnecessarily), so im just trying to optimise this a little better.

It is my understanding that less keys is better.

So having everything seperate EG:

Player1Power: 1

Player1Speed: 2

Player1Level: 3

Player2Power: 3

etc

is terrible compared to having it all as one EG:

PlayerStats: 1;2;3;1;3;2;1;etc

This also makes it a little hard to read though visually if I wanted to log into playfab and play around with it. So another thing im trying to figure out is, is the storing of the data the problem or the transfering?

If its simply the transferring, then would I be just as well off storing the data seperatly (Player1Power, Player1Speed, etc) and simply have a RetrieveStats Cloud Script function that takes those 15 keys, makes 1 key out of them and sends that to the client?

Likewise another one for saving the stats - getting sent 1 key, pulling it apart and saving the 15 keys seperatly.

If that is a good option, my goal would be to have 1 Save function that can pull apart any string, figure out how many keys it needs to become and save a dynamic number of keys from it.

If its the number of keys in the database as the problem, would I be good to do what im doing (save larger strings even if only a small bit of them is the relevant changed data) or would I be even better off - sending a cloud function something like "3;2" - the function would then change the 3rd character in the saved string to "2".

- or, call a function that would act as a 'UpgradePlayer1Power' which would change the 3rd char in the saved string to a +1.

(is sending 'no' data best/fastest when sending to the cloud? So having a separate cloud function for every thing I want to save and calling each one properly, or having a function I can send some indicators to to tell it 'give me player 1's power')

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

The basic answers are that

1) Fewer, larger keys are best if you're using the older Player Data model. The issue is that each separate row is a separate write to the data table, and sub-1KB data is the same amount of work as 1KB. But that small of an amount of data would also easily fit in an Entity Object, which would be even better. https://api.playfab.com/docs/tutorials/entities/getting-started-entities

2) Minimizing calls as much as possible is important, both to prevent excess load on the service, but also to prevent irritating your players if you're on a platform that uses batteries (draining them more quickly) or has bandwidth restrictions or costs.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

squigglyo avatar image squigglyo commented ·

Ok so if im understanding that correctly.

If I want to have all my data thing seperate and not mushed together for the sake of optimization/space, I should use Entities.

Entities, somehow (still reading through it), allow me to save many bits of data but do so in a way that minimizes the effort/data/space?

0 Likes 0 ·
brendan avatar image brendan squigglyo commented ·

Either way, when it comes to Entity Objects. You could use one Object for that, or several. You only have a few to work with per Entity though, so it might be better to have it in one.

0 Likes 0 ·
squigglyo avatar image squigglyo commented ·

After playing around with entities, ive gotten it working.

From what I can figure out, the user gets 3 sets of data per title and 3 for the publisher.

These are simply just a JSON string.

So it would seem that by sending {Player1Power: 1} to the entitity to save, the server would then update do its thing and uupdate that value like it would with legacy data, difference being, the entity is basically 1 giant string, so it does things better/faster.

SO starting fresh with playfab, Im guessing no matter the pros/cons, I should be using entities regardless, since they are the new way to go and the default I should build from.

0 Likes 0 ·
brendan avatar image brendan squigglyo commented ·

Correct - Entity data is the newer model, so I'd encourage going with it, as we'll be focusing our efforts on improving it going forward.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.