Help?

So, I’m nearly at the end of my rope in terms of trying to learn Python…
I have updated to Blender 2.49a and Python 2.6.2 only to find that every Python+Blender tutorial online was written before the large rewrite that took place in the Python language. I’ve been doing my best to follow this tutorial, but I’ve run into a roadblock at every turn. The resulting script from the tutorial makes a cylinder move around on a plane, and is

cont = GameLogic.getCurrentController()
own = cont.getOwner()

#Sensors:

forward = cont.getSensor(“Up”)
backward = cont.getSensor(“Down”)
turnleft = cont.getSensor(“Left”)
turnright = cont.getSensor(“Right”)

#Actuators

motion = cont.getActuator(“motion”)

#Process

speed = 5
rspeed = 0.02
walk = 0
turn = 0

if forward.isPositive():
walk = speed
if backward.isPositive():
walk = -speed
if turnleft.isPositive():
turn = rspeed
if turnright.isPositive():
turn = -rspeed

motion.setLinearVelocity(0, walk, 0, 1)
motion.setDRot(0, 0, turn, 1)
GameLogic.addActiveActuator(motion, 1

What I’ve come up with as a modified version that almost works with the new Python is

cont = GameLogic.getCurrentController()
own = cont.owner
motion = cont.actuators[“motion”]

#Sensors

forward = cont.sensors[“Up”]
backward = cont.sensors[“Down”]
turnright = cont.sensors[“Right”]
turnleft = cont.sensors[“Left”]

#Actuators

speed = 5
rspeed = 0.02
walk = 0
turn = 0

if forward.positive:
walk = speed
if backward.positive:
walk = -speed
if turnright.positive:
turn = rspeed
if turnleft.positive:
turn = -rspeed

motion.setLinearVelocity[0,walk,0,1]
motion.setDRot[0,0,turn,1]
GameLogic.addActiveActuator[motion,1]

When I try to run this in the game, the console thingy tells me that the “‘builtin_function_or_method’ object is unsubscriptable” in line 28: motion.setLinearVelocity[0,walk,0,1]

I think it’s talking about the “motion” variable i’ve made, and i can’t seem to find a solution that works.

I’m a total noob at this coding stuff, but i have to start somewhere. Thanks.

(Also, there are indents below the “if” statements in my script. They just didn’t show up when i copied the script here for some reason)


motion.setLinearVelocity[0,walk,0,1]
motion.setDRot[0,0,turn,1]
GameLogic.addActiveActuator[motion,1]

You cannot call a function with square brackets; you must use parenthesis (round brackets, like these.

Change the above code to this, and it might work (It’s really late, I’m going to sleep now, so my programming might be impaired):


motion.setLinearVelocity([0,walk,0], 1)
motion.applyRotation([0,0,turn], 1)
cont.activate(motion)

Based on how tired I am, I’ve probably messed something up, but hopefully somebody will correct me.

Check out the Blender 2.49 Game Engine API Docs.