Vaibhav
Vaibhav

Reputation: 713

blender game engine import error

i just started learning blender and its scripting and tried to run its 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: No module named 'bge' i searched for a solution but couldn't find any.how to solve this problem? i am using blender 2.65

Upvotes: 8

Views: 4648

Answers (2)

weitao su
weitao su

Reputation: 1

  1. import 'bge' must be 'blender game', rather than blender rendering
  2. give an 'always' run python scripts in 'game logic editor'
  3. start game

Upvotes: 0

fecub
fecub

Reputation: 944

Running import bge does not work when you press "Run script" or try to issue this command in the terminal. You have to press "P" to activate game engine mode. To run your script, connect a controller to the script.

Upvotes: 11

Related Questions