I can see that if I do the following instead:
Quote: /table2 = {} table.foreach (table[1], function (k) table.insert (table2, k) end) table.sort(table2) tprint(table2) I get a sorted set of the headings like this:
Quote: 1="attack1"
2="finish1"
3="level"
4="name" Next question... how do I get that back into the main table, and iterate the sorting over the table[1] through table[45] in a less painful way... I'm guessing it'll be a table.foreach done on the table itself... but... I'm so confused on how to get it back. I did search the forum and didn't find anything that seemed to be regarding this directly before I posted... :(
Edit: Trying this does work, but doesn't do anything because the numbers are already sorted. Just displays the whole list again with 'key' instead of the number, and takes out the indenting.
Quote: /table2 = {} table.foreach (table, function (k) table.insert (table2, k) end) table.sort(table2) for k,v in ipairs (table2) do print ("key =",v) table.foreach(table[v], print) end but if I try to sort one of the actual fields, like this:
Quote: /table2 = {} table.foreach (table[1], function (k) table.insert (table2, k) end) table.sort(table2) for k,v in ipairs (table2) do print ("key =",v) table.foreach(table[1][v], print) end I get the following error:
Quote: [string "Command line"]:1: bad argument #1 to 'foreach' (table expected, got string) If I understand properly, this means that it's not actually able to do the sorting itself again, right? Because if I do have it doing the lookup properly, I could have it saving the values to a temporary third table, then overwrite the first table segment with the third table... or is there a better way to do this? *sighs* |