So I’ve created a little system that displays the stats of an item when you hover of it it’s probably not the best, but like whatever it works although I recently tried to make it like maybe a bit more efficent and was wondering if something like this was possible.
So I have an item that looks like this or I mean all my items look like this, but this is just one of them
Although the issue here is not all the items have these same stats so it’s gonna error and so I decided what if I did something like this
for i,v in pairs(items[item]) do
if i == "Strength" or i == "Agility" or i == "Defense" then
itemInfoFrame.Stats.Text = i..":".." "..v.."\n"..i..":".." "..v.."\n"..i..":".." "..v.."\n"
end
end
And ok so obviously this doesn’t work, but is it possible to do this and if so how? I feel like it could be better I wouldn’t have to use seperate text labels for each stat and like yeah lol.
Once you do that, you can just have the script iterate through items[item].Stats and for each key, value pair, just clone a text label that has text like “key..":"..v” For positioning, you can use a UIListLayout
Oh alright I can try this out however I actually found out I could do this a few seconds ago lmao
local emptyString = ""
for i,v in pairs(items[item]) do
if i == "Strength" or i == "Agility" or i == "Defense" then
emptyString ..= i..":".." "..v.."\n"
end
end
and this also seems to be able to do what I was trying to achieve.
Wouldn’t I end up having to do this? And end up having a lot of ifs lol.
if items[item]["Stats"]["Strength"] then
itemInfoFrame.Power.Text = "Strength: "..items[item]["Stats"]["Strength"]
end
if items[item]["Stats"]["Agility"] then
itemInfoFrame.Agility.Text = "Agility: "..items[item]["Stats"]["Agility"]
end
if items[item]["Stats"]["Stamina"] then
itemInfoFrame.Stamina.Text = "Stamina: "..items[item]["Stats"]["Stamina"]
end
--etc for each stat