I would like to find the best possible method to use when storing player owned inventory items in a database. I will be using a unique Id assigned to each item for storage.
Currently I have a few methods in mind. The methods are listed below:
-
Boolean value of all items in the market will be stored in the player database. If the player owns a specific item, the value is set to true.
-
A single string or boolean value which updates/added when a new item is bought. This is then stored in the player database
Out of these options, what would be the best method to use for storage. If there is a better method other than the list I mentioned, let me know.
I usually save a table of all the player’s info like this:
Key = userid Value = table
TABLE
INDEX AMOUNT VAL TYPE INFO
1 5 INT user backpack items
2 1 BOOL user completed the daily challenge
the motivation is that a table can be dynamically changed as opposed to saving just 1 type of value
also I am against saving an array of booleans of everything because it is way too much data
it should be a dynamic list of unique item IDs - this way it saves up much space and is cost effective
the player owns items 15, 97, 34 for example. save all items in a modulescript table with consistent numbers as indexes and u can quickly get all the data needed in O(1)
2 Likes
Best way is an array, get it inside a dictionary and you can have multiple things. Then just loop through the array and get the items. Easier than doing if data[12] then ...
like @rotbotrotbot mentioned
local data = {
items = {10, 14}, -- normal array, you can loop through it to add the items
otherThing = false,
money = 10273
}
1 Like
I understand how useful a table can be. I will be using it as the value for my key in the player database. Though, the content that will be inside the table is the answer I’m looking for.
I agree, option 1 is a stretch as, not all players will play long enough to get all the items in game. Hence, a waste of space in the database.
So storing the Id/Code of items bought/owned should be stored in a array within the database. Sounds good.
yes that’s how it is being done, I just tried to give an explanation