Chilco Posted May 18, 2010 Share Posted May 18, 2010 Hello people, I already made a little system to collect points by playing games in (race) dd/dm. You can see the points in TAB (I created a column) Now I wanna make a top 10 of the players with the most points. I already made a GUI with 10 labels (1. [NAME] ([NUMBER POINTS] Points) 2. [NAME] ([NUMBER POINTS] Points) etc.) Now I need help, I dont know how to make it. If someone can help me, that will be great. -Chilco Link to comment
50p Posted May 18, 2010 Share Posted May 18, 2010 You can easily sort values within SQL queries. That's only if you use SQL tables to store points. You can also sort numbers in tables. points = { 4, 6, 7, 8, 5, 9 } table.sort( points ); for k, v in ipairs( points ) do print( k .. ". " .. v ); end --[[ 1. 4 2. 6 3. 7 4. 8 5. 5 6. 9 ]] If you want the highest to be on top and the lowest on bottom then you have to make a function which will compare 2 numbers and return the higher one. And use this function in table.sort function. Like so: table.sort( points, function( a, b ) return a > b end ); --[[ output: 1. 9 2. 8 3. 7 4. 6 5. 5 6. 4 ]] If you want to know more about table.sort function or sorting in Lua go here: http://www.lua.org/manual/5.1/manual.ht ... table.sort http://www.lua.org/pil/19.3.html Link to comment
Dark Dragon Posted May 19, 2010 Share Posted May 19, 2010 easier than a 1 line way to do it? i doubt it just go with table.sort it works very well. Link to comment
Chilco Posted May 20, 2010 Author Share Posted May 20, 2010 Can you give me an example? (sorry but I'm newbie in lua ) Link to comment
50p Posted May 20, 2010 Share Posted May 20, 2010 Can you give me an example?(sorry but I'm newbie in lua ) I gave you example... Link to comment
Chilco Posted May 21, 2010 Author Share Posted May 21, 2010 I don't understand youre example Sorry Link to comment
The_Ex Posted May 22, 2010 Share Posted May 22, 2010 Maybe spend some time studying table.sort not look for easier way to do it. 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