Python script not working in BGE

I’m reading Beginning Blender and trying to use a little Python in the BGE. A sphere rolls down a ramp and then drops off a plane. The following script is meant to reset the initial position after it falls:
import bge
object = bge.logic.getCurrentController().owner

if object.worldPosition2 < -3:
object.worldPosition = 0,8.62,2.84
object.linearVelocity = 0,0,0

I have a sensor on the sphere set to Always with pulse true enabled. I have a Python controller set to the script in the text editor window. I push P and the sphere rolls off and doesn’t come back. The position to reset to is the coordinates for the original location.

It would be easier if you give us your example .blend :wink:

Not too familiar with the bge, but looking at your code


if object.worldPosition.z &lt; -3:

[2]

Thanks, that fixed it. I’m getting the hang of Python. It’s the only language I’ve encountered where whitespace matters, in that the amount of indentation is significant. Fortunately I’ve discovered how to display the terminal window so I can read the error messages and debug now.