======== Mainloop ======== .. _mainloop: .. index:: BGE: mainloop .. |a| image:: /images/all/blender-game-engine/arrows.jpg :width: 100px Objectives ========== .. tabularcolumns:: | c | l | :border: none +-------+-------------------------------------------------------------------------+ | |a| |In this part you learn how to write a little program for the game engine | | |which uses a mainloop. | +-------+-------------------------------------------------------------------------+ Instructions ============ :Tasks: 1. Copy the example 2. Add keys and functions Preparations ============ 1. Open a new blend-file 2. Change the render engine from »Blender Render« to »Blender Game« 3. Change to the scripting area and create the file main.py in the text editor 4. Click now in the scene settings in the menu item *Custom Properties* on »add« .. image:: /images/all/blender-game-engine/custom_properties.png 5. Click on »edit« set *Property Name* to »__main__« and *Property Value* to »main.py« .. image:: /images/all/blender-game-engine/add_custom_property_main.png The script ========== First import the module of the Blender Game Engine, bge. .. literalinclude:: files/main.py :language: python :lines: 2 :ATTENTION: You can't run the script with *Run Script* now, because the module bge can only be imported, if the Game Enigne is active. You can start the program now by clicking »P« while the cursor is over the »3D-View«. .. literalinclude:: files/main.py :language: python You can find the keys under `Blender Game Engine -- events `_. More about Blender and the Game Enigne under `Blender Game Engine -- API `_