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.
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|
Stops the sound driver using DSP effects.
Only the fmod sound driver supports this. DSP can be computationally expensive.
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).|
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
True value used by some modules.
False value used by some modules.
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
Applicable to Distance constraint:
Activate alignment to surface
Activate distance control
Direction of the ray is along the local axis
Applicable to Force field constraint:
Force field act on rotation as well
Applicable to both:
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
Substract bits to state mask
Copy state mask
Invert bits to state mask
Add bits to state mask
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
Current camera position
User a timer for the uniform value.