the underminer wrote:
Can anyone help me out?
Code: Select all
-- sorting test
function sorteren(a,b)
if a<b then
return false
else
return true
end
end
table = {}
table[1] = 3
table[2] = 1
table[3] = 2
table.sort(table,sorteren(table[i],table[i+1]))
This is my favorite time to let you know your doing everything all wrong.
Isnt that fun :-)
First problem. You are defining table as a table. When table is a function command list. (So if you use table.sort it will error out) instead try something like "data" or test..
instead of trying to call your own custom function to use a sort method.
All you require is something simpler. Here lets try this.
Code: Select all
data = {2,1,3}
table.sort(data, function(table1,table2) return table1>table2 end)
Another thing you might want to look into is sub arrays.
Code: Select all
data = {
["blah1"] = { "random", 32, "miscdata" }
["blah2"] = { "random", 12, "miscdata" }
["blah3"] = { "random", 64, "miscdata" }
}
table.sort(data, function(table1,table2) return table1[2]>table2[2] end)
Thats right its that simple.
Heres what I did there.
I used an indexed table (table.sort works on any type of table)
Sub tables are refered to by keys in that case id i was refering to sort it was on the second index (so if there is no id(#=) then you can refer to it by its location based on last placed.
If you have any other questions feel free to post. :-)