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 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 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.
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.
A list of attached SCA_PythonJoystick. The list size is the maximum number of supported joysticks. If no joystick is available for a given slot, the slot is set to None.
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: |
|
---|---|
Return type: |
Note
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.
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) |
---|
Returns a list of currently loaded libraries.
Return type: | list [str] |
---|
Loads a scene into the game engine.
Note
This function is not effective immediately, the scene is queued and added on the next logic cycle where it will be available from getSceneList
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 |
---|
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). |
---|
Gets the key used to exit the game engine
Returns: | The key (defaults to bge.events.ESCKEY) |
---|---|
Return type: | int |
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 current .blend or runtime file to make a full path name. 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 for all the active scenes, not only the current scene.
Returns: | The estimated 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
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.
See bge.types.KX_ArmatureSensor.type
Detect that the constraint is changing state (active/inactive)
Value : | 0 |
---|
Detect that the constraint linear error is above a threshold
Value : | 1 |
---|
Detect that the constraint linear error is below a threshold
Value : | 2 |
---|
Detect that the constraint rotation error is above a threshold
Value : | 3 |
---|
Detect that the constraint rotation error is below a threshold
Value : | 4 |
---|
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.BL_ArmatureActuator.type
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
Value : | 0 |
---|
Enable the constraint.
Value : | 1 |
---|
Disable the constraint (runtime constraint values are not updated).
Value : | 2 |
---|
Change target and subtarget of constraint.
Value : | 3 |
---|
Change weight of constraint (IK only).
Value : | 4 |
---|
Change influence of constraint.
Value : | 5 |
---|
See bge.types.KX_ConstraintActuator.option
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
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.KX_SoundActuator
Value : | 1 |
---|
Value : | 2 |
---|
Value : | 3 |
---|
Value : | 4 |
---|
Value : | 5 |
---|
Value : | 6 |
---|
See bge.types.KX_SteeringActuator.behavior
Value : | 1 |
---|
Value : | 2 |
---|
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 |
---|
See bge.types.BL_ArmatureChannel.rotation_mode
Use quaternion in rotation attribute to update bone rotation.
Value : | 0 |
---|
Use euler_rotation and apply angles on bone’s Z, Y, X axis successively.
Value : | 1 |
---|
Use euler_rotation and apply angles on bone’s Y, Z, X axis successively.
Value : | 2 |
---|
Use euler_rotation and apply angles on bone’s Z, X, Y axis successively.
Value : | 3 |
---|
Use euler_rotation and apply angles on bone’s X, Z, Y axis successively.
Value : | 4 |
---|
Use euler_rotation and apply angles on bone’s Y, X, Z axis successively.
Value : | 5 |
---|
Use euler_rotation and apply angles on bone’s X, Y, Z axis successively.
Value : | 6 |
---|
See bge.types.BL_ArmatureConstraint.type
See bge.types.BL_ArmatureConstraint.ik_type
constraint is trying to match the position and eventually the rotation of the target.
Value : | 0 |
---|
Constraint is maintaining a certain distance to target subject to ik_mode
Value : | 1 |
---|
See bge.types.BL_ArmatureConstraint.ik_flag
Set when the constraint operates on the head of the bone and not the tail
Value : | 1 |
---|
Set when the constraint tries to match the orientation of the target
Value : | 2 |
---|
Set when the armature is allowed to stretch (only the bones with stretch factor > 0.0)
Value : | 16 |
---|
Set when the constraint tries to match the position of the target.
Value : | 32 |
---|
See bge.types.BL_ArmatureConstraint.ik_mode
The constraint tries to keep the bone within ik_dist of target
Value : | 0 |
---|
The constraint tries to keep the bone outside ik_dist of the target
Value : | 1 |
---|
The constraint tries to keep the bone exactly at ik_dist of the target.
Value : | 2 |
---|
See bge.types.SCA_PythonKeyboard, bge.types.SCA_PythonMouse, bge.types.SCA_MouseSensor, bge.types.SCA_KeyboardSensor
See bge.types.KX_GameObject.playAction
Play the action once.
Value : | 0 |
---|
Loop the action (repeat it).
Value : | 1 |
---|
Play the action one direct then back the other way when it has completed.
Value : | 2 |
---|
Blend layers using linear interpolation
Value : | 0 |
---|
Adds the layers together
Value : | 1 |
---|
Current camera position
User a timer for the uniform value.
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 |
---|