Still returning nil, I think this is just a different way of doing the same thing.
EDIT: May have just thought of something that might be breaking it, if there is only one value in the table then I assume it would not add anything to sorted table, correct?
However, if you’d like to achieve that result, you could do something like this instead:
local SortedTable = UnsortedTable
table.sort(SortedTable,
function(Value1, Value2)
return Value1[2] > Value2[2]
end
)
By the way, when I first posted this I made a mistake (which I already fixed now). Remember to set the table that is used in table.sort's first argument to SortedTable, not UnsortedTable (just like in the script above).
That should work, but you have a minor mistake. It should be this:
local Table = {} --contains values to be sorted...
local function Sort(Value1, Value2)
return Value1 > Value2
end
table.sort(Table, Sort)
print(Table) --> prints sorted
Tables are not implicitly copied with the assignment operator, so doing local SortedTable = UnsortedTable will only create a variable SortedTable that is a direct reference to UnsortedTable. You can just pass the single variable to table.sort
For copying the unsorted table, you would have to do a shallow copy like this:
local SortedTable = table.pack(table.unpack(UnsortedTable))
--and then
table.sort(SortedTable, Sort)
Right. I didn’t realize that you were storing tables in the table. That also means the shallow copy example in my previous reply wouldn’t work as you would need a deep copy, but it doesn’t matter anyways because you don’t need that.