I want to sort a table based on the the value of the “Size” field within it, but I am not sure how to get table.sort() to help out?
tinytable = {}
tinytable[1] = { Size=2, Shape=3}
tinytable[2] = { Size=3, Shape=2}
tinytable[3] = { Size=1, Shape=1}
The most obvious way to sort this would be:
table.sort(tinytable, function(a,b) return a.Size<b.size end><br>However that merely reorders the value of the Size settings without adjusting the rest of the table, ie:<br><br>[code]<br>tinytable[1] = { Size=1, Shape=3}<br>tinytable[2] = { Size=2, Shape=2}<br>tinytable[3] = { Size=3, Shape=1}
Is there a way to compare based on the value (eg: Size) but sort entire {} entries?
(No, function(a.Size,b.Size) does not work. Shucks.)
Thanks again fellas
[import]uid: 41884 topic_id: 13716 reply_id: 313716[/import] </b.size>