getOwner() with several objects....

Hi folks, need python help please :stuck_out_tongue:

I’m trying to access several objects linked to the same script (same controller). I’ve seen it mentioned here something like:

obj1 = cont.getOwner("obj1")
obj2 = cont.getOwner("obj2")

…but I can’t get that to work, theres no errors (helpful %| ), it just returns the first object connected. Soooo…where am I going wrong? and what is the argument passed to getOwner()? I’ve been assuming it’s the object’s name but is this even possible… :-?

thanks in advance… :smiley:

cheers
Piran

getOwner() returns the owner of the current Logicbrick. You can’t give along a name.
If you want to get the objects linked to a single python controller then you’ve got to get the sensors and then get their owners.

For example:

controller = GameLogic.getCurrentController()

sensor1 = controller.getSensor("sensor_from_object_1")
sensor2 = controller.getSensor("sensor_from_object_2")

obj1 = sensor1.getOwner()
obj2 = sensor2.getOwner()

or shorter:

controller = GameLogic.getCurrentController()

obj1 = controller.getSensor("sensor_from_object_1").getOwner()
obj2 = controller.getSensor("sensor_from_object_2").getOwner()

Hope that helps.

Ahhhh…thanks muchly :smiley:

the example i was looking at didn’t say where it was getting the owner from…now it makes sense :stuck_out_tongue:

cheers
Piran