Python Controller¶
See also
See the Python reference of this logic brick in SCA_PythonController
.
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 Blender’s API.
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:
A file myscript.py
contains:
def myModule ():
print("Go Open Source!");
The function can 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 to Script and setting the name to myscript.py.
Parts of the Python Controller¶
- Type
Specifies whether it is a module or entire file.
- Name
The name of the file to be loaded.
- D (Use Debug)
Continuously reloads the file.
See standard controller parts for descriptions of the remaining options.
See also
For more information on the Python API, see: