Get object which has a certain property equal to x

Hello,

I wonder if someone could help me:
The scene contains an object which has a property named A for example.
A = “some string”.
Is there a way to get that object only knowing what his property A is equal to (in the example “some string”)?
Like: return the object which property A is equal to “some string”.

This is to differentiate objects added by the add object actuator (the added objects have all the same name so they are indistinguishable)

A way to do it would be to use a near sensor that use a long distance and set it up to look only at the property A then return the objects. For each object I would test if their property A is equal to “some string” and I’ve got my object. But I was hoping there was an easier way, a more straight forward way.

This method should work:



sce = logic.getCurrentScene()
for object in sce.objects:
     if property in object:
          if property == "some string":
               found = object # You found the object with the property specified here.


This might be less CPU-intensive, because the Near sensor (I’ve heard) is really bad on the CPU.

Thank you very much!
I’ll try that as soon as possible.

And now I know the near sensor is possibly bad on the CPU, thank:)