How can I have a property represent how far away an object is from another?
Measure to faces

The near sensor detects when any face of an object's (physics) hull is within a certain distance. This is especially good when you work with in-homogeneous formed shapes such as planes, poles, streets, fences. But this can be a pretty slow detection even in native code.

While a near sensor provides you with all the information you need a Python controller to evaluate that results. Be aware the distance will be the distance to the center - not to the nearest face. 

detector.py:

PROPERTY_DISTANCE = "distance"

def distanceToProperty(controller):
    nearSensor = controller.sensors[0] 
    if not nearSensor.positive:
        return

    center = controller.owner
    for hitObject in nearSensor.hitObjectList:
        hitObject[PROPERTY_DISTANCE] = center.getDistanceTo(hitObject)


You can control the filter via the GUI: 



Near/Radar/Collision sensor [True Level Triggering] --&gt; Python controller Module: detector.distanceToProperty


Measure to distance

In difference to the near sensor this method measures to the center of the object only. This is good on homogeneous formed shapes such as spheres, cubes, house.

The evaluating code is the same as before. The difference is that you need to perform the sensing via Python. That means your Python controller acts as a sensor (but is no sensor). To do that you have to constantly trigger the Python controller.

detector.py:

PROPERTY_DISTANCE = "distance"
PROPERTY_DETECTABLE = "detectable"

def distanceToProperty(controller):
    center = controller.owner
    for object in center.scene.objects:
        if PROPERTY_DETECTABLE in object:
            object[PROPERTY_DISTANCE] = center.getDistanceTo(object)




Always sensor [True Level Triggering] --&gt; Python controller Module: detector.distanceToProperty