Hello! I’m working on trying to group up players into two teams of 5 based on their ratings. The goal is to take all player’s MMR values which is the 2nd value in each array in the local variable in QueueTable. Then out of the values given to find the fairest match possible by having teams MMR sum as close as possible.
local QueueTable = {
{"P1userId", 300};
{"P2userId", 240};
{"P3userId", 275};
{"P4userId", 255};
{"P5userId", 255};
{"P6userId", 325};
{"P7userId", 310};
{"P8userId", 225};
{"P9userId", 200};
{"P10userId", 175};
{"P11userId", 150};
{"P12userId", 225};
{"P13userId", 245};
}
for _, Table in pairs(QueueTable) do
table.sort(Table, function(a,b)
return a[1] < a[2]
end)
end
--print(unpack(QueueTable))
for _, Table in pairs(QueueTable) do
for i, int in pairs(Table) do
if i == 2 then
print(int)
end
end
end
In the last for loop, I’m able to separate the MMR values from the string values. However, when I try sorting it in the previous for loop. I get an error for attempting to index a number with a number at “return a[1] < a[2]” a is the MMR value and b is the string value. I want to sort the tables by lowest MMR value to highest. I can’t separate the MMR value from the string value since that will be holding the userid so the server knows who to match who.
Once the tables are sorted It would simplify match making process. How can I sort the tables?