If your code is not performance critical, it may be easier to have a table of tables instead, something like:
lua Code:
local buffs = { -- Unsorted buffs table
{1234, 25},
{4321, 60}
}
for i, v in ipairs(buffs) do
print(i, v[1], v[2])
end
--[[ Output:
1 1234 25
2 4321 60
]]
local function compare(a, b)
return a[2] > b[2]
end
table.sort(buffs, compare)
for i, v in ipairs(buffs) do
print(i, v[1], v[2])
end
--[[ Output:
1 4321 60
2 1234 25
]]
-- Now to find a specific buff ID and get the healing value, you could use something like:
local function getHealing(id)
for _, v in ipairs(buffs) do
if v[1] == id then return v[2] end
end
return nil -- Functions return nil by default, but whatever
end
local healing = getHealing(1234) -- Returns 25
healing = getHealing("this buff does not exist") -- Returns nil