To my understanding, you can't sort an associative array like this because lua tables have no ordering mechanism (think about hashmaps). However arrays can be sorted, because arrays are tables where each value's key is numerical.
Since what you want is to get is an array of your table's keys sorted following the associated value in the table, you must: 1. Extract all keys in your table into an array
local keys={}for k inpairs(choices)dotable.insert(keys,k)end
2. Sort your array of keys along the values in your original table
Comments
To my understanding, you can't sort an associative array like this because lua tables have no ordering mechanism (think about hashmaps). However arrays can be sorted, because arrays are tables where each value's key is numerical.
Since what you want is to get is an array of your table's keys sorted following the associated value in the table, you must:
1. Extract all keys in your table into an array
3. Now your keys arrays is ordered the way you want and you can concat them.