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

Deciding between two item storage ideas?

Asked by 5 years ago

I have two ideas for handling data storage that I needed to decide between. I was wondering if one is objectively better, or if there's a better way of doing things;

Method One

I have a modulescript that has each item in the game and its characteristics, like so;

local items = {
    ["weapons"] = {
        ["sword"] = {
            ["attack"] = 10,
            ["speed"] = 20,
            # other stats etc
            }
    },
    ["accessories"] = {
        ["necklace"] = {
            ["magic defence"] = 30,
            }
        }
    }
}

Or something to that effect. When a player obtains an item, I get the item from this module script and add it to their inventory (which will be held in another module script that contains all players' data while they are playing) and the item will be saved (with another modulescript) with all it's characteristics.

But that got me thinking about how I would change an item's stat's if it's already in a player's inventory; especially if they can be upgraded or anything like that. Which leads me on to method two;

Method Two

Identical to the first method, except rather than saving the item to the player's inventory, a string is saved with the name of that item, and maybe some characteristic unique to that player's instance of the item (level, stats(?) holding base stats in the item modulescript or something) and when the player joins, the a script finds the items that they own using the strings that would have been set and adds it to their inventory.

The upside I was considering regarding this strategy is that if I want to change an item, whenever a player joins a server, their item will have the changed characteristics. Say there is a sword with 10 attack and I want it to have 5 attack, I can just change it in the module script and all players with the sword will have the one with 5 attack.

Or, is there a better method that I haven't thought of? Any feedback would be really appreciated.

extra question: why do people use stuff like"userid"..userId to set asyncs? Is there a difference between that and just userIdor is it just readability?

0
To answer your extra question; preference. User#24403 69 — 5y

Answer this question