I’m working on an rpg and so having a custom rpg is needed.
In my old rpg’s when the player deletes an item, it would loop through the Inventory table and delete the first value it comes across with the same damage, removes it and then breaks the loop. This isn’t a problem because the items weren’t different ( so 1 “Learners Sword” would be the exact same as another “Learners Sword”) though it could be annoying to some.
With my rpg, weapons are gonna have varying stats (random attack value chosen between two other values, elements, etc) so I can’t do what I do normally.
I was thinking about giving each item a unique ID when an item is added starting at 1 for the player.
Ex. Player begins the game with a Learners Sword (ID 1). He then gets a Health Potion (ID 2).
Then when I loop through the inventory to display the items, I’d set a value or whatever to the ID of the item, then when the player clicks it; it would loop through the inventory table and remove the item with that ID.
The only problem I can imagine if eventually it hit’s the highest number (can’t remember it exactly but I think it’s 2^32 (possibly * 10)) then the Inventory is gonna break.
I know it’s really unlikely for that to happen ( there’s 25 slots for each category: weapons, armour, consumables and materials) but I’d like to know if there’s a better way to do it. Thanks.
I plan to limit the Inventory. But say the player uses up all 25 slots in each category, then uses all those items / deletes them. Then fills up all 25 slots in each category again, that’s the ID at 100 now.
Like I said It’s only a small possibility of it reaching the highest number possible, but just curious if there’s a better / different way.
So you’re creating a new entry in a datastore whenever a weapon is generated because its stats are randomized. You then save the ID of this newly generated item. That’s no good. Why not just store the stats of the item in the inventory itself?
For example, assuming your inventory could have gaps in it like a typical RPG, you can serlalize your inventory like so:
inventory = {
["1"] = {
id = "starterSword",
damage = 1234
},
["2"] = nil, -- blank space in the inventory
["3"] = {
id = "smallHealthPotion",
}
}
So say the player selects the last item they have in the Weapon part of the Inventory, it would loop through the Weapon Inventory and delete the value with the same ID instead of the first item it comes across with the same name.