Ok, I know this questions has already been answerd in: "http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5514", and that table.sort is explained here: "http://www.lua.org/manual/5.0/manual.html#5.4"
But I still dont get it, maybe Im an complete idiot or something but how does table.sort work?
This is how my current test.lua file looks like, im trying to figure out how table.sort is working but no mather what I do, I dont get it to work.
The "afflictions" table is "alot" bigger in the real file.
This is my current scripting error message when trying to call function test2:
attempt to compare two table values
stack traceback:
[C]: in function `sort'
[string "Script file"]:20: in function `test2'
[string "Command line"]:1: in main chunk
The main file is alot bigger and more complicated but since I cant event get this one to work I dont see the reason to bring the whole thing up here.
One more thing, this is proberly quite important. In my main file I want to sort a table like:
table1 = {
{ name = "addiction"},
{ name = "agoraphobia"},
}
after the priority stated in table2 where name in table1 is equal to the name in table2.
table2 = {
{ name = "addiction", priority = "8", syntax = "eat nightshade" },
{ name = "agoraphobia", priority = "7", syntax = "eat orphine" },
}
But I still dont get it, maybe Im an complete idiot or something but how does table.sort work?
This is how my current test.lua file looks like, im trying to figure out how table.sort is working but no mather what I do, I dont get it to work.
afflictions = {
{ name = "addiction", priority = 8 },
{ name = "agoraphobia", priority = 7 },
{ name = "asthma", priority = 6 },
{ name = "claustrophobia", priority = 9 },
{ name = "clumsiness", priority = 6 },
{ name = "confused", priority = 10 },
}
function test1()
for k, v in afflictions do
Note("Name: " .. tostring(v.name) .. ". Priority: " .. tostring(v.priority))
end
end
function test2()
table.sort (afflictions)
end
The "afflictions" table is "alot" bigger in the real file.
This is my current scripting error message when trying to call function test2:
attempt to compare two table values
stack traceback:
[C]: in function `sort'
[string "Script file"]:20: in function `test2'
[string "Command line"]:1: in main chunk
The main file is alot bigger and more complicated but since I cant event get this one to work I dont see the reason to bring the whole thing up here.
One more thing, this is proberly quite important. In my main file I want to sort a table like:
table1 = {
{ name = "addiction"},
{ name = "agoraphobia"},
}
after the priority stated in table2 where name in table1 is equal to the name in table2.
table2 = {
{ name = "addiction", priority = "8", syntax = "eat nightshade" },
{ name = "agoraphobia", priority = "7", syntax = "eat orphine" },
}