Simon54 Posted July 25 Share Posted July 25 Hello Community. I need a bit of help with sorting some numbers inside a table starting from the lowest value to the highest. The numbers inserted into the table will be math.random but for this exercise we're using numbers: 2, 4, 6, 8 and 10. My question is, with the following example down below is there a simple way to make them output in the order of: 2, 4, 6, 8, 10 instead of: 10, 8, 2, 6, 4 ? numTable = {} -- insert table.insert(numTable, 10) table.insert(numTable, 8) table.insert(numTable, 2) table.insert(numTable, 6) table.insert(numTable, 4) -- sort -- output outputChatBox(tostring(numTable[1])..", "..tostring(numTable[2])..", "..tostring(numTable[3])..", "..tostring(numTable[4])..", "..tostring(numTable[5])) Link to comment
Tekken Posted July 25 Share Posted July 25 Hello, may this help you? https://www.lua.org/pil/19.3.html 1 Link to comment
fxl Posted July 25 Share Posted July 25 numTable = {} -- insert table.insert(numTable, 10) table.insert(numTable, 8) table.insert(numTable, 2) table.insert(numTable, 6) table.insert(numTable, 4) -- sort table.sort(numTable) output: 2 4 6 8 10 as provided before: https://www.lua.org/pil/19.3.html 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now