get object property

does anyone know if I can get an object AND its property state (true or false) using: object.getHitObject()

I’m trying to do a simulation of an infection outbreak among a small group of people. It’s very simplified and abstract, but that’s ok. Basically I have a bunch of cylinders with some random motion moving around an arena bumping into each other. If one of the cylinders has a property of infected==true, then the one he bumped into also gets infected.
They can also have an “immune” property. Anyways, I need to be able to check the properties of an object using the Near sensor.
Any ideas?

ho = sensor.getHitObject()
if ho and ho.propertyname:
   do stuff

Use this code to infect on collision:

HitObject = Collision.getHitObject()
HitObject.Infected = 1

Collision would be a collision sensor.

To check with a near sensor it would be something like:

HitObjects = Near.getHitObjectList()

for Object in HitObjects:

    Owner.InfectedObjects += 1

Hope this helps.

ok, I’m still not getting it to work.
here is what I’m trying:

import GameLogic
import Rasterizer

controller = GameLogic.getCurrentController()
object = controller.getOwner()
sensor = object.getSensor("near")
sensed = sensor.getHitObject()

if sensed and sensed.infected:
     object.infected = True

?

Hi,
I found two errors in your script, here is a ‘correct’ version with some comments:

import GameLogic
import Rasterizer

controller = GameLogic.getCurrentController()
object = controller.getOwner()
sensor = controller.getSensor("near")#getSensor() is a controller method
sensed = sensor.getHitObject()

if sensed and sensed.infected:
     object.infected = 1 #every value but 0

Bye!
P.S. : Have a look Here!
You’ll find there almost all the anwers to the questions you’ll encounter with Python in Blender.

thanks very much!
it works now!