Python Q's

  • I have an object colliding, and on collision, prints the objects name. Why does it always trigger, giving me NoneType errors?
  • I have an object colliding, and on collision, needs to set location. I thought it would just be Object.Location = 0, 0, 0 or Object.Location = Spawn.Location. I have tried this with Location(), Loc, and Loc() too. None work :smiley: (PS, the object is gotten with col.getHitObject(), where col is the colision sensor)
  • How can I go about import the modules to allow the except statement (is it a statement?) in Blender Game Engine?
  1. I’m going to guess you aren’t filtering the pulses. The sensors fire off a negative and a positive pulse. If every other time gives you that error then do something like the following:

cont = GameLogic.getCurrentController()

col = cont.getSensor("col")

if col.isPositive():
    ob = col.getHitObject()
    
    print ob.name
  1. Try object.setLocation()

  2. You don’t need to import anything. Just use it:

try:
    stuff
except:
    print "Oops"

object.position = [0,0,0]
object.setPosition([0,0,0])

Both work

moguri. i love you.

so that’s what true and false triggering are for? true only sends out positives, false negatives? Or if I select False Level Triggering, that filters OUT negative pulses? cause I’ve always wanted to know :smiley: Also, i forgot the ‘try’. oops :smiley:

Bluesocarrot: that’s weird :smiley: i have know idea what i was doing, but for some reason, i was being stupid. i got it thanks :smiley:

not sure what it can be used for but use this for a python index…
http://www.tutorialsforblender3d.com/GameFunctions/GameLogicPage1.html
or…
http://www.blender.org/documentation/pydoc_gameengine/PyDoc-T2-Gameengine-2.34/indices.html