In MMF there was an object called the "layer object" that could do things like, sort all the objects/sprites according to a private variable - so you could make it so that the higher the variable then those objects would appear in front of objects with a lower value.
I tried doing something similar by:
always - start loop "sdf" 100 times
then if sprite variable = the loopindex "sdf", then send to front
but this seems to slow the game down a bit?