I tried to make a system what includes table.sort(), but with failure...
table.sort(My_Table, 3)
As of my knowedge, unless you want a specific way to sort the table you don't need a second parameter as it sorts from smallest to largest by default. However, if you want to sort in a special way such as from largest to smallest, table.sort()
requires a function as a second parameter to sort the array. For example, if I have table :
local t = { {"Data1", 2}, {"Data4", 4}, {"Data0", 0} }
and if I were to reorder the table from largest to smallest by second value of each table I would have a function that sorts this.
local t = { {"Data1", 2},--what I mean by second value is , {"Data1(First Value)",2(Second Value)} {"Data4", 4}, {"Data0", 0} } table.sort(t,--the table I want to sort function(a,b) --a function to sort the value. by default, it sorts from least to greatest. return a[2]>b[2] -- if the second value of "A" is greater than "B" then return true end) for I,v in pairs(t) do print(tostring(v[1]).."|"..tostring(v[2])) end