table.sort problem
Hi, I'm unsure if this is possible. But basically I want everything with 100 chance to be at the top then sorted by priority. Anything with not 100 chance I want to sort by priority only.
Example table: _cmds = { { chance = 50, priority = 1 }, { chance = 100, priority = 10 }, { chance = 100, priority = 7 }, { chance = 75, priority = 5 }, } What I've tried: table.sort(_cmds, function(a,b) if a.chance == 100 and b.chance ~= 100 then if a.priority < b.priority then return true else return false end else if a.priority < b.priority then return true else return false end end end) Would like the table to end up looking like this: _cmds = { { chance = 100, priority = 7 }, { chance = 100, priority = 10 }, { chance = 50, priority = 1 }, { chance = 75, priority = 5 }, } |
Try
Code:
Code:
_cmds = { Code:
_cmds = { |
Thank you, it work't perfectly!
Now that I see the code and think about it, it makes sense. I just could'nt figure it out myself :S Hopefully next time I will. Thanks a bunch Quote:
|
All times are GMT -5. The time now is 01:57 PM. |
vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI