• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Need help with logic to ordenate tables..

lucas123

New Member
Joined
Jun 6, 2010
Messages
85
Reaction score
4
how can I sort tables within a table?

like that (Original table):
Code:
local spells = {
--
{
instantName = 'Flame Strike',
words = 'exori flam',
lvl = 10,
mana = 20,
prem = false,
exhaustion = 1000,
groups = 1,
icon = 89,
needlearn = false,
vocations = {1,2,5,6},
},
--
{
instantName = 'Energy Strike',
words = 'exori vis',
lvl = 300,
mana = 20,
prem = false,
exhaustion = 10000,
groups = 1,
icon = 90,
needlearn = false,
vocations = {1,2,5,6},
},
--
{
instantName = 'Terra Wave',
words = 'exevo tera hur',
lvl = 30,
mana = 200,
prem = false,
exhaustion = 2000,
groups = 1,
icon = 91,
needlearn = false,
vocations = {1,2,5,6},
},
--
}


Sorted table:
Code:
local spells = {
--
{
instantName = 'Flame Strike',
words = 'exori flam',
lvl = 10,
mana = 20,
prem = false,
exhaustion = 1000,
groups = 1,
icon = 89,
needlearn = false,
vocations = {1,2,5,6},
},
--
{
instantName = 'Terra Wave',
words = 'exevo tera hur',
lvl = 30,
mana = 200,
prem = false,
exhaustion = 2000,
groups = 1,
icon = 91,
needlearn = false,
vocations = {1,2,5,6},
},
--
{
instantName = 'Energy Strike',
words = 'exori vis',
lvl = 300,
mana = 20,
prem = false,
exhaustion = 10000,
groups = 1,
icon = 90,
needlearn = false,
vocations = {1,2,5,6},
},
--

}

(ordenating by lvl of secundary table..)
how can i do it?
thanks
 
that's a tableception
Lua:
table.sort(spells, function(first, second) return first.lvl < second.lvl end)
 
Back
Top