Error importing blender engine

I just started to study blender and its scripts and tried to run my sample code

import bge def main(): cont = bge.logic.getCurrentController() own = cont.owner sens = cont.sensors['mySensor'] actu = cont.actuators['myActuator'] if sens.positive: cont.activate(actu) else: cont.deactivate(actu) main() 

and get the following error: ImportError: There is no module named 'bge' I searched for a solution but could not find it. How to solve this problem? i am using blender 2.65

+8
python blender
source share
2 answers

Starting bge import does not work when you click "Run script" or try to execute this command in the terminal. You must press "P" to activate the game engine mode. To run the script, connect the controller to the script.

+12
source share
  • import 'bge' should be a "blender game", not a blender rendering
  • give "always" run python scripts in the "game logic editor"
  • start the game
0
source share

All Articles