Chilco Posted May 18, 2010 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
50p Posted May 18, 2010 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
Dark Dragon Posted May 19, 2010 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.
Chilco Posted May 20, 2010 Author Posted May 20, 2010 Can you give me an example? (sorry but I'm newbie in lua )
50p Posted May 20, 2010 Posted May 20, 2010 Can you give me an example?(sorry but I'm newbie in lua ) I gave you example...
The_Ex Posted May 22, 2010 Posted May 22, 2010 Maybe spend some time studying table.sort not look for easier way to do it.
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