Changeset View
Changeset View
Standalone View
Standalone View
game_engine/logic/controllers/python.rst
| Context not available. | |||||
| Python Controller | Python Controller | ||||
| ***************** | ***************** | ||||
| The python controller runs a python script when a sensor triggers the controller. | |||||
| This python script can interact with the scene or logic bricks through the :doc:`blender game engine API </game_engine/python_api/index>`. | |||||
| A python script can either run as an entire file or a single module. | |||||
| A file must be added in the text editor, and is identified simply by its name, not its path. Names are case sensitive. Modules are identified by the file name *without* the extension followed by a ``.`` and then the name of the module. For example: | |||||
| myscript.py | |||||
| .. code-block:: python | |||||
| def myModule (): | |||||
| print("Go Open Source!"); | |||||
| will be accessed as ``myscript.myModule``, which will run ``print("Go Open Source!");`` every time the controller is triggered. | |||||
| The entire file can be run by setting the type dropdown to script and setting the name to myscript.py. | |||||
| Parts of the python controller: | |||||
| ================================= | |||||
| .. image:: /images/python_controller_screenshot.jpg | |||||
| 1. Type: Specifies whether it is a module or entire file | |||||
| 2. The name of the file to be loaded | |||||
| 3. Continuously reload the file. | |||||
| The :doc:`remaining parts </game_engine/logic/controllers/editing>` are standard to all controllers. | |||||
| More information on the python API can be found :doc:`here </game_engine/python_api/index>` | |||||
| Context not available. | |||||