pythonblenderbpy

Blender Game Engine - bge Module Not found


I have looked at other forums and did not find an answer to my problem, i know that for bge the script only works when connected to logic bricks, and just to be sure i was typing it the right way i watched a bge tutorial on youtube and it worked for him but not for me.

how do i download the bge module? any suggestions would be greatly appreciated

also i noticed after i watched the video the blender console said this:

Error:

Python script error - object 'Cube', controller 'Python':
Traceback (most recent call last):
File "moveX.py", line 1, in <module>
ImportError: No module named 'Bge'
Blender Game Engine Finished

Script:

import bge

def main():
    cont = bge.logic.getCurrentController()
    owner = cont.owner  
    owner.positive.x += 0.1

main()

Solution

  • Yes the bge module is a part of the game engine and is available through a python controller logic brick. This python controller is only activated when the game engine is actually running.

    While you can build blender without the game engine I wouldn't expect it to be disabled unless you have compiled your own version of blender. The error you see will always happen if you run a script using bge outside of the game engine, such as from blender's text editor.

    First enable the game engine by selecting it in the render engine menu.

    render engine menu

    Then after setting up your script in the python controller, press P to start the game engine.

    EDIT:

    The error in your question indicates you have import Bge in your script, the bge should be all lowercase, which you seem to have fixed in the script you added. The script will get a different error as there is no positive property in an object, you will want to use owner.position.x

    import bge
    
    def main():
        cont = bge.logic.getCurrentController()
        owner = cont.owner  
        owner.position.x += 0.1
    
    main()