hello;
i am new in scripting. i am trying to sort my objects in an array according to their z position value. İ mean have 10 objects in the scene and they are randomly positioned in z axis. How can i manage to sort them in an array according to their z position value
thanks
Solved! Go to Solution.
Solved by blakestone. Go to Solution.
You can use qsort to define your own functions and how you want your array sorted - below is sorting the selection based on the z position
( local my_selection = selection as array fn sort_z v1 v2 = ( local result = v1.position.z - v2.position.z ) qsort my_selection sort_z for i in my_selection do print i )
v1 - v2 = accending || v2 - v1 = decending... I have adjusted the script so you can simply set the mode: 1 = accending || 2 = decending
Hopefully this makes sense?
( local my_selection = selection as array local mode = 1 -- *** 1 = accending | 2 = decending *** fn sort_z v1 v2 = ( if (mode == 1) then local result = v1.position.z - v2.position.z else if (mode == 2) then local result = v2.position.z - v1.position.z ) qsort my_selection sort_z for i in my_selection do print i )