Excal,
I do not want download your file or analyse your code, because it can be simpler than you're thinking...
First of all, distance is a trick if you're dealing with a non static object.
But, I did the job by using instance variables, setting the objects who need to be checking against another object by storing their "Distances" inside this instance variable, then, pick the object with the higher/lower "Distance".
So:
= Every tick:
= For each Obstacle:
-> Set instance variable "Distance" to [distance(Player.x,Player.y,Obstacle.x,Obstacle.y)]
= Pick lowest "Distance" from Obstacle:
-> Do whatever you want...
Avoid making objects with the same exactly distance, or, the system will sort one of them...
If it's not possible, simple make an index, so, put inside the "Distance" a dot and plus, an index, like the IID or UID, and the system will always pick the objects with the same distance, but will select the smaller IID or UID or another instance variable, like ID, its your choice...