Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I save a player's inventory with DataStore?

Asked by 8 years ago

Hi, I'm kind of a newbie to the whole 'DataStore' thing, so I have a question.

If I created a game that involves a player inventory (for storing hats, weapons, and other items), how could I save that inventory with DataStore? (for different places in a universe) And if I had character creation, how could I save a player's character(s)?

Thank you, -Nen

0
Do you mean you don't how to use datastore or don't know how to save that kind of stuff? theCJarmy7 1293 — 8y
0
I can probably figure out DataStore, so mostly I just don't know how to save that kind of stuff. Nengalore 25 — 8y
0
To save this kind of stuff, just save a string full of the items in the inventory, then load it up by looping through the table and giving the players the items theCJarmy7 1293 — 8y
0
Not sure I totally understand, would you mind giving me an example? Nengalore 25 — 8y

2 answers

Log in to vote
0
Answered by
Vexture 179
8 years ago

As a rewording to eLunate's answer to help you understand:

Represent every "item" in your inventory with a numerical ID Give each item properties or whatever you want, also represented by values

save these values in a table

when you start the game, you just sort through that table and insert those items into the inventory based on the ID and properties of that item; essentially "interpret" the values that you saved.

0
Yes, sure, but how would I save a table? Nengalore 25 — 8y
0
Here's how datastore works: You create a unique "key" for each player (based on their user ID, preferably) and with that "key" you can save a table of values using the :SetAsync() method (i.e. datastore:SetAsync(key,tableofvalues)). Vexture 179 — 8y
0
I'll try it thanks. Nengalore 25 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Serialization

Once you know what you want to save, saving your stuff is fairly trivial. Serialization works like this: You describe the item you want to save, rather than saving every single bit of data.


In an inventory example, you have to consider how you want to save the Inventory. Is it a bunch of slots? We can use a table to represent that, and each slot can be a new entry. What's in the slot? If it's an item, we have to consider how we can describe that item:

  • What is the item's unique identifier? What is the item class?
  • Was the item randomly generated? What was the seed to generate it?
  • Does the item have a level? What level is it?

Save all the details you need, but not the actual item. When you load it again, you can use those details to rebuild all of the items in the inventory.

0
I'm not intending to make a class or level based MMO type game, nor would there be randomly generated items, so that could be a bit of an issue. Nengalore 25 — 8y
0
Doesn't matter. It's not an issue if you know what you're trying to save. User#6546 35 — 8y
0
Look. The point is, if your game selected it somehow, then you can save how it selected it. User#6546 35 — 8y
0
I may understand, but I'm not sure if that would work for me. Nengalore 25 — 8y
0
Serialization is how you will do it. I don't care if you think it will work, because it will work if you do it right. Every single item will have something which can identify it, and you can use that information to find it again in your game. User#6546 35 — 8y

Answer this question