(Blender 2.5) Can someone help me fix this simple python script?

Hi.


from bge import logic
cont = logic.getCurrentController()
scene = logic.getCurrentScene()

go = cont.sensors['coll']
pt = cont.actuators['Parent']
ho = go.hitObject
if go.positive:
    pt.setObject(ho)
    cont.activate(pt)

The script is supposed to use sensor “collider” to detect when the object hits an object with the property “PHY”, and, when it does, to parent the sphere to the object it hits.

It doesn’t work.

Any ideas?

Edit: Is it just me or was BlenderArtists down for 6 hours?

BlenderArtists messes up a lot - for some reason, it goes down for hours at a time every so often. I don’t really know what the problem is - hopefully it can get fixed.
As far as I can tell, you refer to cont.sensors[‘coll’], but the sensor is called ‘collider’, right? Try renaming it. If there’s a problem with your script, check the code console - it will show the script’s errors.

The sensor is actually called ‘coll’. I’ve checked for little errors like that several times.
Blender console doesn’t tell me there are any issues.

Add some print statements. Then you can see what the code is doing.

e.g.:

from bge import logic
cont = logic.getCurrentController()
scene = logic.getCurrentScene()

go = cont.sensors['coll']
pt = cont.actuators['Parent']
ho = go.hitObject
if go.positive:
  pt.setObject(ho)
  cont.activate(pt)
  print ("activated %s to parent %s to %s" % (pt.name, pt.object.name, pt.owner.name) )
else:
  print ("sensor %s of %s is not positive" % (go.name, go.owner.name) )

I hope it helps