I have an Inventory System and I’ve come across an issue between choosing which method would be best. Please note each item has A LOT of data looking something like this:
local ItemTemplate = {
Id = "",
Level = 1,
Experience = 100,
["Max Experience"] = 5000,
Tags = {},
Skills = {
TemplateSkill = {
SkillId = "Tackle",
Level = 1,
Experience = 100,
MaxExperience = 100
}
},
Enchants = {
-- more stuff here
TemplateEnchant = {
EnchantId = "Enchant",
Level = 1,
Experience = 100,
MaxExperience = 1000,
}
}
}
And as you can see the tables can stack quite quickly. (Sorry for the bad indenting)
Method 1 : Clear and Update
This method is generally very simple and requires barely any code. All I would need is 2 functions:
local function clearInventory()
-- delete everything in the inventory (UI)
end
local function loadInventory()
clearInventory()
-- load
end
Downsides:
- Sometimes if you have a lot of times users will notice a “flash” in the inventory updating it.
Upsides:
- Simple and not complex
Method 2 : Compare And Update
This step isn’t more complex but time-consuming and can be tricky. Every update, I’d have to loop through the current Inventory, compare items, look for missing items or items that shouldn’t exist and then take action, but this would require me to compare tables which would require a lot of iteration loops.
Downsides:
- Time consuming, can be tricky
Upsides:
- No flickering glitch
Between the 2, I’m not sure which would be better in terms of performance in code, but I’d like to know what I should be doing and is there an easy way to compare tables on the client.