Well, the "object position X()" is a value all by itself, so I (and the compiler) have no idea how it relates to your "dist" tag. Even if define the object using the type command of object.dist as integer the "object position x()" would be the location of the object without regard to the "object.dist" value.
in other words; Object position x() is a number returned by direct-x itself -- ie; where is this object in the 3D space? The .dist value is that local number you use to locate the object, not where direct-x thinks it is. (big difference there.)
As for the function of dist() versus the variable of dist#, dist# may or may not be global but the function dist() is always global. Dist() is a called operation, ie; do the code after the function declaration and possibly return a value from it. Dist# is a variable, which can be global dist# or it can be local if used in a function as dist(dist#, x, y).
If that has not confused the heck out of you I'd suggest you don't make functions with the same name as your variables, for the very reason above.
But basically, you are not finding the object position correctly in your if statement, the .dist extension has nothing to do with the object position x() command.
s.
Any truly great code should be indisguishable from magic.