1
$\begingroup$

my code:

import bge

def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner

    #variables

    ACCEL=0.01
    MAXSPEED=1
    BRAKE=0.1
    TURN=0.5
    speed=0
    gear=1

    #sensors and actuators

    up = cont.sensors['u']
    back = cont.sensors['d']
    left = cont.sensors['l']
    right= cont.sensors['r']
    brake = cont.sensors['b']
    clutch= cont.sensors['c']
    gearUp = cont.sensors['g']
    move = cont.actuators['movement']

    ##############program##########

    #throttle

    if up.positive :
        speed+=ACCEL*gear

    #gearup

    if speed*gear >= MAXSPEED*gear and gearUp.positive:
        gear+=1

    #turn
    if left.positive:
        speed-=TURN
        motion.DRot(0,0,-10)

    if right.positive:
        speed-=TURN
        motion.DRot(0,0,10)   

main()
$\endgroup$
2
  • $\begingroup$ Have you looked at the console? (as sambler already mentioned, this is Blender behavior, rather than BGE behavior). $\endgroup$ Commented Dec 1, 2016 at 12:37
  • $\begingroup$ did you press the "Run Script" button in the text editor? Because this is bge code it will only work in game. $\endgroup$ Commented Dec 31, 2016 at 4:10

1 Answer 1

2
$\begingroup$

I don't see an error in your script. I expect you are trying to run the script from blender's text editor to get the error, which in the console will show the error as ImportError: No module named 'bge'

To use a script in the game engine you need to assign it to a python controller, the controller will run the script as needed during game play.

python controller

$\endgroup$
1
  • $\begingroup$ good one sambler. I got to this question from the review (where your answer did not show). Now after posting this comment I find your answer. $\endgroup$ Commented Dec 31, 2016 at 4:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.