Python Help

ok, I did a tutorial to help me figure out Python, which can be found HERE

anyway, I followed all of the directions to the letter, and went over it 5 times or more, and it still doesn’t work. I start the game engine, and nothing happens when I press the keys. (the game engine does start)

however, the really weird thing is, I tried copying the code HE wrote into a new text window, and tried it, and it worked! as far as I can tell, my code and his code is exactly the same.

here is my code:

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

#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)

and here is his:

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 am I doing wrong???

You have cont.getOwnder() instead of cont.getOwner() in the second line, otherwise the script looks fine.

Yeah, gomer is right. i’m not sure what an Ownder is :stuck_out_tongue:

FYI, these kinds of errors will show up in the console (the little black text window that launches with blender). It’ll tell you what line has the error, and why.

thanks that fixed it.

also, the console does not launch on my computer. (not in a window I can see) is there a way to tell it to open?

are you on a mac or pc?

I am on a mac

If you want to see the blender terminal on a mac you have to start blender from a terminal.

  • Open a terminal
  • Navigate to /Applications/Blender2.47.app/Contents/MacOS/
  • Type ./blender.Now blender has started and the ‘events’ will show up in the terminal you opened it in!

:ba: Mr T. says if you want to get really cool you could write a shell script!

Good luck!

Also, if you’re working on a compter where the actual console is locked down, you still might be able to use the x11 console (just type “x11” into spotlight) with exactly the same method and results.

or just go into spotlight and type console and use that. You don’t need to type anything