That's not an array. An array is:
{ "a", "b", "c" }
See this page (http://ptxwiki.psycho-chihuahua.net/doku.php/scriptinghelp/tables).
Thanx, bastya_elvtars!
Now I know that it is a table. :)
So, I need to know how to sort it by value (from the smallest to the biggest - like tables's order).
Need variant in lua4 and lua5.
Best regards,
NemeziS
You have keys and values in a table. Let's just see!
tab={["a"]=1,["b"]=2}
Now what to do in order to display it sorted? This way even works if you don't know the contents:
-- lua4
arr={}
for a,b in tab do
tinsert(arr,a)
end
sort(arr)
for k,v in arr do
print(tab[v])
end
-- lua5
for a,b in pairs(table) do
table.insert(arr,a)
end
table.sort(arr)
for k,v in ipairs(arr) do
print(tab[v])
end
Hope this helps.