I found out that…it works when tried with indexed tables, but since my table use keys instead of indexes, it doesn’t work.
Here is a sample code if u wanna try…
local objList = { } local obj1 = display.newCircle(0,0,0) objList["obj1"] = obj1 local obj2 = display.newCircle(0,0,0) objList["obj2"] = obj2 local obj3 = display.newCircle(0,0,0) objList["obj3"] = obj3 local obj4 = display.newCircle(0,0,0) objList["obj4"] = obj4 local obj5 = display.newCircle(0,0,0) objList["obj5"] = obj5 local obj6 = display.newCircle(0,0,0) objList["obj6"] = obj6 obj1.y =10 obj2.y =40 obj3.y =20 obj4.y =50 obj5.y =60 obj6.y =30 local function sortfn(a, b ) return a.y \< b.y end --no matter if u coment this line or not, function will always produce the same result... table.sort(objList, sortfn) for k,v in pairs(objList) do --objList[i]:toFront() print(objList[k].y) end
RESULTS…
40 30 50 60 10 20