The Python controller is a controller that checks the input using a user-programmed script, a.k.a. a Python script or any other file containing Python code. Python controllers have two modes: Script or Module. Both can be written in the text editor and stored inside the .blend file, or they can be external script files. Further explanation of the two modes is given below.
- Execution Method
- This menu state which method the Python code is to be accessed
- script or Module.
- Allows the user to input the name of the script or module file.
In Script mode, the controller is linked to a script, the whole script will be executed before the logic moves on. Everything in the script will happen at the same frame, if the same value or attribute are changed more than once, only the latest will be visible in the game because of this. If for example the position of an object is changed first to (100.0,100.0,100.0) but later in the same script changed to (0.0,0.0,0.0), then only the (0.0,0.0,0.0) will be visible to the player because the move to (100.0,100.0,100.0) happened on at the same frame.
Since Blender 2.49 the Python module controller was added. Simply choose Module instead of Script on your Python controller drop-down menu. Then you define a function on that module and call that function from the controller. Instead of writing “
myScript.py” on the script edit box, you’ll write “
myModule.myFunc” on the module edit box. This function will run every time the controller is called. But other functions and variables outside of
myFunc’s scope will only run once. This is good for optimizing your code when you want to initiate variables only once then use them later.
The Python module controller supports any number of attributes, this means packages are supported automatically. As well as “
myModule.myFunc” you can do “
myPackage.myModule.myFunc”, nested packages work too, as does method calls on class instances like: “
myPackage.myModule.myInstance.myMethod”. The python controller is passed to the python function as an argument for functions that take one arg.
This allows live editing of scripts, learn more about the Python module controller at:
*Thread http://blenderartists.org/forum/showthread.php?t=156672 *Video http://download.blender.org/apricot/live_bge_edit.ogv