Drakath Posted July 1, 2015 Share Posted July 1, 2015 I added some rows with numbers to my GridList but it sorts it from lowest to highest and I want to sort it from highest to lowest. Is there a way to make the sorting the way I want by scripting? Link to comment
undefined Posted July 1, 2015 Share Posted July 1, 2015 Use table.sort. Example: table.sort(table, function(a,b) return a > b end) Link to comment
Drakath Posted July 1, 2015 Author Share Posted July 1, 2015 Use table.sort.Example: table.sort(table, function(a,b) return a > b end) What if the table has a number and a string? myTable[1] is a string and myTable[2] is an integer. Link to comment
undefined Posted July 2, 2015 Share Posted July 2, 2015 Use table.sort.Example: table.sort(table, function(a,b) return a > b end) What if the table has a number and a string? myTable[1] is a string and myTable[2] is an integer. I doesn't try it. If it isn't work, use tostring(integerValue) Link to comment
n3wage Posted July 2, 2015 Share Posted July 2, 2015 What if the table has a number and a string?myTable[1] is a string and myTable[2] is an integer. table.sort(table, function(a,b) return a[2] > b[2] end) Link to comment
Drakath Posted July 2, 2015 Author Share Posted July 2, 2015 What if the table has a number and a string?myTable[1] is a string and myTable[2] is an integer. table.sort(table, function(a,b) return a[2] > b[2] end) I'm still not sure how to use this though. Does this override the original table.sort? Something like this?: table.sort(table, function(a,b) return a[2] > b[2] end) function asdf(theTable) for i, tableValue in ipairs(theTable) do local row = guiGridListAddRow(theList) table.sort(tableValue) guiGridListSetItemText ( theList, row, Column2, tableValue[2], false, true ) end end Link to comment
n3wage Posted July 2, 2015 Share Posted July 2, 2015 What if the table has a number and a string?myTable[1] is a string and myTable[2] is an integer. table.sort(table, function(a,b) return a[2] > b[2] end) I'm still not sure how to use this though. Does this override the original table.sort? Something like this?: table.sort(table, function(a,b) return a[2] > b[2] end) function asdf(theTable) for i, tableValue in ipairs(theTable) do local row = guiGridListAddRow(theList) table.sort(tableValue) guiGridListSetItemText ( theList, row, Column2, tableValue[2], false, true ) end end No, you have to use table.sort in the table (in your example called theTable) before using for loop, see: function asdf(theTable) table.sort(theTable, function(a,b) return a[2] > b[2] end) for i, tableValue in ipairs(theTable) do local row = guiGridListAddRow(theList) table.sort(tableValue) guiGridListSetItemText ( theList, row, Column2, tableValue[2], false, true ) end end Link to comment
Drakath Posted July 2, 2015 Author Share Posted July 2, 2015 There is another problem in this case. theTable is a table that stores more tables. The numbers I need to sort are tableValue[2]. I can't sort theTable because it would try to compare two tables. Should I try to make another table which would store every tableValue[2] and then sort it or is there a better way? Link to comment
Drakath Posted July 3, 2015 Author Share Posted July 3, 2015 So I tried making an extra table for sorting but turns out it messed up the listing. Numbers mixed up so each player in the table got a number of another player. I need another way to sort those numbers. 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