Arranging display hierarchy back and forth

I have 5 objects and they are constantly moving around and I want arrange the display hierarchy according to y cord. The largest y cord will display in front and smallest at the back. Anyone can help? [import]uid: 40786 topic_id: 24507 reply_id: 324507[/import]

throw your objects into a table and then call this function

function sortDepth()  
  
 function byval(a,b) -- comp  
 return a.y \< b.y  
 end  
  
 table.sort(myObjArray,byval)  
  
 for k=1,#petArray do  
 myObjArray[k]:toFront()  
 end  
  
end  

-finefin [import]uid: 70635 topic_id: 24507 reply_id: 99192[/import]