Notifications
Clear all
[Closed] Sort array of objects by xPosition to helper
Aug 04, 2013 4:56 pm
i have a array of objects , i want to sort my array by checking distance of xposition of objects to a Dummy helper.
can anyone help me how do that ?
thankx
5 Replies
Aug 04, 2013 4:56 pm
fn compareDistance obj1 obj2 = (distance obj1 objhelper)>(distance obj2 objhelper)
qSort listObjs compareDistance
4 Replies
thank u dude , but i got this error : Unable to convert: false to type: Integer
my code :
objhelper = $Dummy001
fn compareDistance obj1 obj2 = (distance obj1 objhelper)>(distance obj2 objhelper)
qsort preHelperArrayTop compareDistance
qsort preHelperArrayBottom compareDistance
fn compareDistance obj1 obj2 =
(
if ((distance obj1 objhelper)>(distance obj2 objhelper) ) then
return 1
else
if ((distance obj1 objhelper)<(distance obj2 objhelper) ) then
return -1
else
return 0
)
don’t use return to break a condition in mxs function.
but much faster sort algorithm could be: