I’m working on a game which will allow the player to buy pets. I’m storing the player’s pets as a dictionary in Datastores. An example dictionary would look like this:
{["Dog"] = 1, ["Cat"] = 0} -- 1 means equipped, 0 means stored in inv
The only issue I’m facing is how I should store multiple of the same pet. If the player has two dogs, then how would I be able to differentiate between the two when the player tries to equip one? Dictionary.Dog only returns the latest item in the dictionary.
As for which one is equipped, personally I’d do something like:
Equipped = {
Pet = "SpottyDog"
}
If you go with that method, players can then own more than one of the same item. The number in their inventory represents how many of that item they have.
How would I give each dog a new name though? The player could have up to 100 pets and they could all be the same dog, would I have to generate a new name for each dog in their inventory?
In which case, I would use an array as suggested above.
Pets = {
{
Type = 1, -- dog
Equipped = false,
-- additional pet info
}
{
Type = 1, -- dog
Equipped = true,
-- additional pet info
}
{
Type = 2, -- cat
Equipped = false,
-- additional pet info
}
}