trzistan
(Triz)
October 3, 2020, 2:42am
#1
First of all, I know how to use table.sort . I was wondering how you would add a function in argument two. Any ideas on how to use argument two (function)?
trzistan
(Triz)
October 3, 2020, 2:43am
#2
Nevermind. I figured the solution to this post. There is no need to reply.
sjr04
(uep)
October 3, 2020, 2:44am
#3
What was the solution, so you can help future readers with the same problem.
trzistan
(Triz)
October 3, 2020, 2:44am
#4
After I posted this, I found this post as I searched:
Unfortunately, there’s no easy way around this. Dictionaries, unlike arrays, cannot have an order.
Solution 1 Convert to Array
You’ll need to convert it to arrays like this.
local players = {
{'coolboy123', 216},
{'funfungamers', 683},
{'asdasdasd', 120}
}
And then sort the table with the following code:
table.sort(players, function(a, b)
return a[2] > b[2]
end)
Our table is now:
funfungamers 683
coolboy123 216
asdasdasd 120
Solution 2 spairs
Credit to this StackOverflow post
Here’…
In their code, I just knew how to use it.
1 Like