Module to access logic functions, imported automatically into the python controllers namespace.
# To get the controller thats running this python script: cont = bge.logic.getCurrentController() # bge.logic is automatically imported # To get the game object this controller is on: obj = cont.owner
# To get a sensor linked to this controller. # "sensorname" is the name of the sensor as defined in the Blender interface. # +---------------------+ +--------+ # | Sensor "sensorname" +--+ Python + # +---------------------+ +--------+ sens = cont.sensors["sensorname"] # To get a sequence of all sensors: sensors = co.sensors
See the sensor’s reference for available methods:
You can also access actuators linked to the controller
# To get an actuator attached to the controller: # +--------+ +-------------------------+ # + Python +--+ Actuator "actuatorname" | # +--------+ +-------------------------+ actuator = co.actuators["actuatorname"] # Activate an actuator controller.activate(actuator)
See the actuator’s reference for available methods
Most logic brick’s methods are accessors for the properties available in the logic buttons. Consult the logic bricks documentation for more information on how each logic brick works.
There are also methods to access the current bge.types.KX_Scene
# Get the current scene scene = bge.logic.getCurrentScene() # Get the current camera cam = scene.active_camera
Matricies as used by the game engine are row major matrix[row][col] = float
bge.types.KX_Camera has some examples using matrices.
A dictionary that is saved between loading blend files so you can use it to store inventory and other variables you want to store between scenes and blend files. It can also be written to a file and loaded later on with the game load/save actuators.
only python built in types such as int/string/bool/float/tuples/lists can be saved, GameObjects, Actuators etc will not work as expected.
Gets the Python controller associated with this Python script.
Gets a list of the current scenes loaded in the game engine.
|Return type:||list of bge.types.KX_Scene|
Scenes in your blend file that have not been converted wont be in this list. This list will only contain scenes such as overlays scenes.
Loads bge.logic.globalDict from a file.
Saves bge.logic.globalDict to a file.
Loads the blend file.
|Parameters:||blend (string) – The name of the blend file|
Ends the current game.
Restarts the current game by reloading the .blend file (the last saved version, not what is currently running).
Converts the all of the datablocks of the given type from the given blend.
Asynchronously loaded libraries will not be available immediately after LibLoad() returns. Use the returned KX_LibLoadStatus to figure out when the libraries are ready.
Uses existing datablock data and loads in as a new library.
Frees a library, removing all objects and meshes from the currently active scenes.
|Parameters:||name (string) – The name of the library to free (the name used in LibNew)|
Returns a list of currently loaded libraries.
|Return type:||list [str]|
Loads a scene into the game engine.
This function is not effective immediately, the scene is queued and added on the next logic cycle where it will be available from getSceneList
Sends a message to sensors in any active scene.
Sets the world gravity.
Returns a 512 point list from the sound card. This only works if the fmod sound driver is being used.
|Return type:||list [float], len(getSpectrum()) == 512|
Gets the maximum number of logic frames per render frame.
|Returns:||The maximum number of logic frames per render frame|
Sets the maximum number of logic frames that are executed per render frame. This does not affect the physic system that still runs at full frame rate.
|Parameters:||maxlogic (integer) – The new maximum number of logic frames per render frame. Valid values: 1..5|
Gets the maximum number of physics frames per render frame.
|Returns:||The maximum number of physics frames per render frame|
Sets the maximum number of physics timestep that are executed per render frame. Higher value allows physics to keep up with realtime even if graphics slows down the game. Physics timestep is fixed and equal to 1/tickrate (see setLogicTicRate) maxphysics/ticrate is the maximum delay of the renderer that physics can compensate.
|Parameters:||maxphysics (integer) – The new maximum number of physics timestep per render frame. Valid values: 1..5.|
Gets the logic update frequency.
|Returns:||The logic frequency in Hz|
Sets the logic update frequency.
The logic update frequency is the number of times logic bricks are executed every second. The default is 60 Hz.
|Parameters:||ticrate (float) – The new logic update frequency (in Hz).|
Gets the physics update frequency
|Returns:||The physics update frequency in Hz|
Sets the physics update frequency
The physics update frequency is the number of times the physics system is executed every second. The default is 60 Hz.
|Parameters:||ticrate (float) – The new update frequency (in Hz).|
Gets the key used to exit the game engine
|Returns:||The key (defaults to bge.events.ESCKEY)|
Sets the key used to exit the game engine
|Parameters:||key (int) – A key constant from bge.events|
Render next frame (if Python has control)
Converts a blender internal path into a proper file system path.
Use / as directory separator in path You can use ‘//’ at the start of the string to define a relative path; Blender replaces that string by the directory of the startup .blend or runtime file to make a full path name (doesn’t change during the game, even if you load other .blend). The function also converts the directory separator to the local file system format.
|Parameters:||path (string) – The path string to be converted/expanded.|
|Returns:||The converted string|
Gets the estimated/average framerate for all the active scenes, not only the current scene.
|Returns:||The estimated average framerate in frames per second|
Returns a list of blend files in the same directory as the open blend file, or from using the option argument.
|Parameters:||path (string) – Optional directory argument, will be expanded (like expandPath) into the full path.|
|Returns:||A list of filenames, with no directory prefix|
Returns a random floating point value in the range [0 - 1)
Prints GL Extension Info into the console
Prints engine statistics into the console
Returns a Python dictionary that contains the same information as the on screen profiler. The keys are the profiler categories and the values are tuples with the first element being time taken (in ms) and the second element being the percentage of total time.
True value used by some modules.
False value used by some modules.
Detect that the constraint is changing state (active/inactive)
Detect that the constraint linear error is above a threshold
Detect that the constraint linear error is below a threshold
Detect that the constraint rotation error is above a threshold
Detect that the constraint rotation error is below a threshold
Activate when the property is equal to the sensor value.
Activate when the property is not equal to the sensor value.
Activate when the property is between the specified limits.
Activate when the property changes
Activate when the expression matches
Just make sure the armature will be updated on the next graphic frame. This is the only persistent mode of the actuator: it executes automatically once per frame until stopped by a controller
Enable the constraint.
Disable the constraint (runtime constraint values are not updated).
Change target and subtarget of constraint.
Change weight of constraint (IK only).
Change influence of constraint.
Activate alignment to surface
Activate distance control
Direction of the ray is along the local axis
Force field act on rotation as well
Detect material rather than property
No deactivation if ray does not hit target
Limit X coord.
Limit Y coord
Limit Z coord
Limit X rotation
Limit Y rotation
Limit Z rotation
Set distance along negative X axis
Set distance along negative Y axis
Set distance along negative Z axis
Set distance along positive X axis
Set distance along positive Y axis
Set distance along positive Z axis
Set orientation of X axis
Set orientation of Y axis
Set orientation of Z axis
Set force field along negative X axis
Set force field along negative Y axis
Set force field along negative Z axis
Set force field along positive X axis
Set force field along positive Y axis
Set force field along positive Z axis
Customer filter, the code code is set via shaderText property.
Disable the filter that is currently active
Enable the filter that was previously disabled
Create and enable preset filters
Disable and destroy the filter that is currently active
Use quaternion in rotation attribute to update bone rotation.
Use euler_rotation and apply angles on bone’s Z, Y, X axis successively.
Use euler_rotation and apply angles on bone’s Y, Z, X axis successively.
Use euler_rotation and apply angles on bone’s Z, X, Y axis successively.
Use euler_rotation and apply angles on bone’s X, Z, Y axis successively.
Use euler_rotation and apply angles on bone’s Y, X, Z axis successively.
Use euler_rotation and apply angles on bone’s X, Y, Z axis successively.
constraint is trying to match the position and eventually the rotation of the target.
Constraint is maintaining a certain distance to target subject to ik_mode
Set when the constraint operates on the head of the bone and not the tail
Set when the constraint tries to match the orientation of the target
Set when the armature is allowed to stretch (only the bones with stretch factor > 0.0)
Set when the constraint tries to match the position of the target.
The constraint tries to keep the bone within ik_dist of target
The constraint tries to keep the bone outside ik_dist of the target
The constraint tries to keep the bone exactly at ik_dist of the target.
Play the action once.
Loop the action (repeat it).
Play the action one direct then back the other way when it has completed.
Current camera position
User a timer for the uniform value.
Substract bits to state mask
Copy state mask
Invert bits to state mask
Add bits to state mask