lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Unread 10-14-2020, 03:28 PM
surreal surreal is offline
The Wary
 
Join Date: Oct 2020
Posts: 2
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 },
}
Reply With Quote
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How does ipairs handle deletes from a table? Niwashi Lua Programming Help (L) 1 05-21-2012 05:29 AM
Saving quickslot data to table Marll Lua Programming Help (L) 8 01-07-2011 02:09 PM
LocalPlayer (a table value)? WTH goldbishop Lua Programming Help (L) 4 11-30-2010 05:13 PM
nested table issues SanDBoX Lua Programming Help (L) 1 11-21-2010 02:12 AM
Whats on the table post retail launch? AncientWolf General Authoring Discussion (L) 10 04-27-2007 07:11 AM


All times are GMT -5. The time now is 04:59 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui