Hello, I’ve been trying to sort the following table:
["Bushes"] = 8,
["Cart"] = 3,
["Crates"] = 9,
["Fences"] = 3,
["Fire Crystal"] = 17,
note that the above table is what is printed out when i run print(allRarities)
This is how I’ve set up my table:
local allRarities = {}
local function addElement(i,v)
allRarities[i] = v["Rarity"]
end
I’ve given it a few shots myself and looked at other topics but nothing will work. The closest I’ve gotten is probably this:
table.sort(allRarities,
function(a,b)
return a[2] > b[2]
end
)
for i,v in pairs(allRarities) do
print(i .. " " .. v)
end
but it seems to me like it’s either
- not doing anything
- just sorting the indexes by alphabetical order.
I tried to reverse the index and values in my table, however some indexes have the same value:
["Crates"] = 9,
["Torches"] = 9,
so I don’t think this is doable. Any help at all would be greatly appreciated!
Here’s my expected output:
["Cart"] = 3,
["Fences"] = 3,
["Bushes"] = 8,
["Crates"] = 9,
["Fire Crystal"] = 17,