This is placed in a for loop, so it’s basically gonna be indexing by numbers. The pet ID is just used for finding the pet inside the player, to then equip it. The click multiplier is the number inbetween the two set values. The for loop makes one entry per pet.
Quick summary: I want to get the 5 biggest click multipliers of this table, how should I do it?
It’s how you order stuff. It’s the most reliable way. It’s fairly simple once you get the hang of it. This is used to get leaderbaords and stuff. Because it sorts the biggest(or smallest) int values. And if you want to sort the top five you’ll have to do so. I can write an example if you want.
local highestNumber = 0
for _, v in pairs(clickMultis) do
if v.clickMultiplier > highestNumber then
highestNumber = v.clickMultiplier
end
end
print("Highest number ", highestNumber)
This would get one value that is the highest. But how about I put this in a for loop and remove the one I found from the table, that should get me the very highest, correct?
clickMultis[i] = {
["clickMultiplier"] = (folder.ClickMultiplier1.Value+folder.ClickMultiplier2.Value)/2,
["petID"] = folder.PetID.Value
}
table.sort(clickMultis[i], function(a, b)
return a[2] > b[2]
end)
for i, v in pairs(clickMultis[i]) do
if i <= 5 then
print(v)
end
end
Then the title should not be “How’d I get the 5 biggest values inside a table?”, rather it should be “How’d I get the 5 biggest values inside a dictionary?”
-- Table extentions. So sad that lua has a terribly small set of built in functions.
-- This iterator function returns n amount from t table.
function TakeEnum(t, amount)
local i = 0
return function()
if (i < amount) then
i = i + 1
return i, t[i]
end
end
end
local values = { 1,4,7,3,9,10,8,6,2,5 } -- This is an array table. Change it to that first.
table.sort(values, function(a,b)
return a > b
end)
for k,v in TakeEnum(values, 5) do
print(v)
end
The problem with this script is that it only eats array tables, not associative. Convert clickMultis into that first.
I don’t know how you structured your whole thing so i can’t help you with that.
I’m fresh out of lua school, with experience of 2 months so I’m not sure if this is the proper way of doing things. Let others critique before you use it.