table.sort a 2D Table

I have a table that is populated with values like these:

myTable = {} counter = 0 for i = 1, #MyDBTable do myTable[i] = {} myTable[i].counter = tonumber(math.random(1,8)) myTable[i].name = tostring(math.random(1,8)) end

I was wondering if how can I use the “table.sort” that will sort myTable[i].counter from the least to the greatest value or vice versa. How am I gonna utilize the table.sort? thanks in advance

I think this should work:

[lua]local sort_func = function( a,b ) return a.sort < b.sort end

    table.sort( myTable, sort_func )[/lua]

Judging from your sample you could skip the .counter thing and Google “lua shuffle table” instead.

Wow thanks. Btw what is the inspect in your given sample?(lua shuffle table)

I think this should work:

[lua]local sort_func = function( a,b ) return a.sort < b.sort end

    table.sort( myTable, sort_func )[/lua]

Judging from your sample you could skip the .counter thing and Google “lua shuffle table” instead.

Wow thanks. Btw what is the inspect in your given sample?(lua shuffle table)