Iwasawa Posted March 30, 2015 Posted March 30, 2015 Help me please! I need help with table sorting, im working on AI racers script, and it works fairly good already, but i need to sort them by how many cps did they collect. So i have the Vehicles as keys and the CP collected as value. How can i sort by value? I store the keys as data in the vehicles so i can access the names table with the key of the vehicle.(the AI has names)
Iwasawa Posted March 30, 2015 Author Posted March 30, 2015 OR, is it a working solution to just refresh the whole table in every sec? I mean, i create a new empty table, and add them sorted by their points. Then next sec clear the table and do the same again. Or how do you do this?
Ryancit2 Posted March 30, 2015 Posted March 30, 2015 Clearing the table won't hurt, perhaps a code provided would help us more efficiently to let you know better choice. Although, refreshing tables isn't really CPU-Consuming stuff unless it is related with hugeass database.
Et-win Posted March 30, 2015 Posted March 30, 2015 table.sort(table, function(var1, var2) return var1[1] < var2[1] end) Change to the index where the values are stored.
Iwasawa Posted March 30, 2015 Author Posted March 30, 2015 I dont understand that etwin. How could i sort a 60 entry table with this method?
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