Problems with multiple 'near' sensors

Hey all. I am having an issue with the ‘near sensors’: http://www.pasteall.org/blend/13156

As per the .blend file, I have an object with two ‘near’ sensors (Near and Near1) connected looking for objects with property ‘touchable’. They are both connected to a python script that should print the names of the objects that trigger the ‘near’ sensor. But as you’ll see in the .blend, only one nearObject.name will print out. This can be avoided by having the sensors searching for different properties… but this is not what I need. Is this a bug? Any suggestions?

reCAPTCHA

It’s working they just have the same object being detected by both sensors each time.
found this out by making some changes:


if nearObject != None: 
        print("Near sensor: ",nearObject)#.name)
    
if nearObject1 != None:
        print("Near1 sensor: ",nearObject1)#.name)

“They are both connected to a python script that should print the names of the objects that trigger the ‘near’ sensor.” if you want to have a list of objects detected try ‘sens.hitObjectList.’
When I encounter similar problems like this I usually like to have different strings print out in different parts of the script so I know what parts of the are working and what isn’t.

Hope that helped.:slight_smile:

Thanks. I had figured that this is what is happeneng… now the question is how to resolve the issue so that I can get both objects to be detected.

They are They are just stored in sens/sens1.hitObjectList. Oh I see what you want now(I think)! If I correctly understand what you want, you only need one near sensor. hitObjectList returns a list you can check if a specific object you want is in the list by using:


if "cube1" in sens.hitObjectList:
        code you want to run
if "cube2" in sens.hitObjectList:
        code you want to run

I love you.