OK, so I am running into a bit of a bug with this. It worked great with just one object, however I have some different object I want to use this same approach too. Here is a modified CAPX of yours that I added a new object too, and I am using the same code. It seems that once you get into the range of the new object, it no longer checks the DISTANCE element, only the angle of the others. Not sure if I am making sense.
edfarias.com/games/turret2.capx
I shortened the range of all objects to test this out, but as you move around I think you will notice what is happening.
Thanks again.