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
KX_GameObject and KX_Camera or bge.types.~KX_LightObject methods are available depending on the type of object
# 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 matricies.
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.
Note
only python built in types such as int/string/bool/float/tuples/lists can be saved, GameObjects, Actuators etc will not work as expected.
The current keyboard wrapped in an SCA_PythonKeyboard object.
The current mouse wrapped in an SCA_PythonMouse object.
Gets the Python controller associated with this Python script.
Return type: | bge.types.SCA_PythonController |
---|
Gets the current Scene.
Return type: | bge.types.KX_Scene |
---|
Gets a list of the current scenes loaded in the game engine.
Return type: | list of bge.types.KX_Scene |
---|
Note
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.
Parameters: |
|
---|
Uses existing datablock data and loads in as a new library.
Parameters: |
|
---|
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) |
---|
Loads a scene into the game engine.
Parameters: |
|
---|
Sends a message to sensors in any active scene.
Parameters: |
|
---|
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 |
---|---|
Return type: | integer |
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 |
---|---|
Return type: | integer |
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 |
---|---|
Return type: | float |
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 |
---|---|
Return type: | float |
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 |
Return type: | string |
Gets the estimated average framerate
Returns: | The estimed average framerate in frames per second |
---|---|
Return type: | float |
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 |
Return type: | list |
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.
Value : | 1 |
---|
Activate when the property is not equal to the sensor value.
Value : | 2 |
---|
Activate when the property is between the specified limits.
Value : | 3 |
---|
Activate when the property changes
Value : | 4 |
---|
Activate when the expression matches
Value : | 5 |
---|
See bge.types.BL_ActionActuator
See bge.types.KX_ConstraintActuator.option
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
See bge.types.KX_ConstraintActuator.limit
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
See bge.types.KX_SCA_DynamicActuator
See bge.types.SCA_RandomActuator
See bge.types.KX_SceneActuator
See bge.types.BL_ActionActuator
See bge.types.KX_SoundActuator
Value : | 1 |
---|
Value : | 2 |
---|
Value : | 3 |
---|
Value : | 4 |
---|
Value : | 5 |
---|
Value : | 6 |
---|
See bge.types.SCA_PythonKeyboard, bge.types.SCA_PythonMouse, bge.types.SCA_MouseSensor, bge.types.SCA_KeyboardSensor
See bge.types.KX_StateActuator
See bge.types.KX_StateActuator.operation
Substract bits to state mask
Value : | 0 |
---|
Copy state mask
Value : | 1 |
---|
Invert bits to state mask
Value : | 2 |
---|
Add bits to state mask
Value : | 3 |
---|
Value : | 2 |
---|
Customer filter, the code code is set via shaderText property.
Value : | 12 |
---|
Value : | 4 |
---|
Disable the filter that is currently active
Value : | -1 |
---|
Enable the filter that was previously disabled
Value : | -2 |
---|
Value : | 5 |
---|
Value : | 9 |
---|
Value : | 11 |
---|
Value : | 6 |
---|
Create and enable preset filters
Value : | 1 |
---|
Disable and destroy the filter that is currently active
Value : | 0 |
---|
Value : | 8 |
---|
Value : | 10 |
---|
Value : | 3 |
---|
Value : | 7 |
---|
Current camera position
User a timer for the uniform value.