Module GameLogic
[frames | no frames]

Module GameLogic

Documentation for the GameLogic Module.

There are only three importable modules in the game engine:

All the other modules are accessible through the methods in GameLogic.

See WhatsNew for updates, changes and new functionality in the Game Engine Python API.

Examples:
       # To get a controller:
       import GameLogic
       co = GameLogic.getCurrentController()
       
       # To get the game object associated with this controller:
       obj = co.getOwner()
KX_GameObject and KX_Camera or KX_Light 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 = co.getSensor("sensorname")

       # To get a list of all sensors:
       sensors = co.getSensors()
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.getActuator("actuatorname")
       
       # Activate an actuator
       GameLogic.addActiveActuator(actuator, True)
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 KX_Scene:
       # Get the current scene
       scene = GameLogic.getCurrentScene()
       
       # Get the current camera
       cam = scene.active_camera
Matricies as used by the game engine are row major:
       matrix[row][col] = blah
KX_Camera has some examples using matricies.
Function Summary
  addActiveActuator(actuator, activate)
Activates the given actuator.
SCA_PythonController getCurrentController()
Gets the Python controller associated with this Python script.
KX_Scene getCurrentScene()
Gets the current Scene.
float getLogicTicRate()
Gets the logic update frequency.
float getPhysicsTicRate()
Gets the physics update frequency
  getRandomFloat()
Returns a random floating point value in the range [0...1)
list [float], len(getSpectrum()) == 512 getSpectrum()
Returns a 512 point list from the sound card.
  setGravity(gravity)
Sets the world gravity.
  setLogicTicRate(ticrate)
Sets the logic update frequency.
  setPhysicsTicRate(ticrate)
Sets the physics update frequency
  stopDSP()
Stops the sound driver using DSP effects.

Variable Summary
    Constants
  KX_TRUE: True value used by some modules.
  KX_FALSE: False value used by some modules.
    Property Sensor
  KX_PROPSENSOR_EQUAL: Activate when the property is equal to the sensor value.
  KX_PROPSENSOR_NOTEQUAL: Activate when the property is not equal to the sensor value.
  KX_PROPSENSOR_INTERVAL: Activate when the property is between the specified limits.
  KX_PROPSENSOR_CHANGED: Activate when the property changes
  KX_PROPSENSOR_EXPRESSION: Activate when the expression matches
    Constraint Actuator
  KX_CONSTRAINTACT_LOCX: See KX_ConstraintActuator
  KX_CONSTRAINTACT_LOCY: See KX_ConstraintActuator
  KX_CONSTRAINTACT_LOCZ: See KX_ConstraintActuator
  KX_CONSTRAINTACT_ROTX: See KX_ConstraintActuator
  KX_CONSTRAINTACT_ROTY: See KX_ConstraintActuator
  KX_CONSTRAINTACT_ROTZ: See KX_ConstraintActuator
    IPO Actuator
  KX_IPOACT_PLAY: See KX_IpoActuator
  KX_IPOACT_PINGPONG: See KX_IpoActuator
  KX_IPOACT_FLIPPER: See KX_IpoActuator
  KX_IPOACT_LOOPSTOP: See KX_IpoActuator
  KX_IPOACT_LOOPEND: See KX_IpoActuator
    Random Distributions
  KX_RANDOMACT_BOOL_CONST: See SCA_RandomActuator
  KX_RANDOMACT_BOOL_UNIFORM: See SCA_RandomActuator
  KX_RANDOMACT_BOOL_BERNOUILLI: See SCA_RandomActuator
  KX_RANDOMACT_INT_CONST: See SCA_RandomActuator
  KX_RANDOMACT_INT_UNIFORM: See SCA_RandomActuator
  KX_RANDOMACT_INT_POISSON: See SCA_RandomActuator
  KX_RANDOMACT_FLOAT_CONST: See SCA_RandomActuator
  KX_RANDOMACT_FLOAT_UNIFORM: See SCA_RandomActuator
  KX_RANDOMACT_FLOAT_NORMAL: See SCA_RandomActuator
  KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL: See SCA_RandomActuator
    Action Actuator
  KX_ACTIONACT_PLAY: See BL_ActionActuator
  KX_ACTIONACT_FLIPPER: See BL_ActionActuator
  KX_ACTIONACT_LOOPSTOP: See BL_ActionActuator
  KX_ACTIONACT_LOOPEND: See BL_ActionActuator
  KX_ACTIONACT_PROPERTY: See BL_ActionActuator
    Sound Actuator
  KX_SOUNDACT_PLAYSTOP: See KX_SoundActuator
  KX_SOUNDACT_PLAYEND: See KX_SoundActuator
  KX_SOUNDACT_LOOPSTOP: See KX_SoundActuator
  KX_SOUNDACT_LOOPEND: See KX_SoundActuator
  KX_SOUNDACT_LOOPBIDIRECTIONAL: See KX_SoundActuator
  KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: See KX_SoundActuator

Function Details

addActiveActuator(actuator, activate)

Activates the given actuator.
Parameters:
actuator
           (type=SCA_IActuator)
activate - whether to activate or deactivate the given actuator.
           (type=boolean)

getCurrentController()

Gets the Python controller associated with this Python script.
Returns:
SCA_PythonController

getCurrentScene()

Gets the current Scene.
Returns:
KX_Scene

getLogicTicRate()

Gets the logic update frequency.
Returns:
The logic frequency in Hz
           (type=float)

getPhysicsTicRate()

Gets the physics update frequency
Returns:
The physics update frequency in Hz
           (type=float)

getRandomFloat()

Returns a random floating point value in the range [0...1)

getSpectrum()

Returns a 512 point list from the sound card. This only works if the fmod sound driver is being used.
Returns:
list [float], len(getSpectrum()) == 512

setGravity(gravity)

Sets the world gravity.
Parameters:
gravity
           (type=list [fx, fy, fz])

setLogicTicRate(ticrate)

Sets the logic update frequency.

The logic update frequency is the number of times logic bricks are executed every second. The default is 30 Hz.
Parameters:
ticrate - The new logic update frequency (in Hz).
           (type=float)

setPhysicsTicRate(ticrate)

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 - The new update frequency (in Hz).
           (type=float)

stopDSP()

Stops the sound driver using DSP effects.

Only the fmod sound driver supports this. DSP can be computationally expensive.

Variable Details

KX_TRUE

True value used by some modules.

KX_FALSE

False value used by some modules.

KX_PROPSENSOR_EQUAL

Activate when the property is equal to the sensor value.

KX_PROPSENSOR_NOTEQUAL

Activate when the property is not equal to the sensor value.

KX_PROPSENSOR_INTERVAL

Activate when the property is between the specified limits.

KX_PROPSENSOR_CHANGED

Activate when the property changes

KX_PROPSENSOR_EXPRESSION

Activate when the expression matches

KX_CONSTRAINTACT_LOCX

See KX_ConstraintActuator

KX_CONSTRAINTACT_LOCY

See KX_ConstraintActuator

KX_CONSTRAINTACT_LOCZ

See KX_ConstraintActuator

KX_CONSTRAINTACT_ROTX

See KX_ConstraintActuator

KX_CONSTRAINTACT_ROTY

See KX_ConstraintActuator

KX_CONSTRAINTACT_ROTZ

See KX_ConstraintActuator

KX_IPOACT_PLAY

See KX_IpoActuator

KX_IPOACT_PINGPONG

See KX_IpoActuator

KX_IPOACT_FLIPPER

See KX_IpoActuator

KX_IPOACT_LOOPSTOP

See KX_IpoActuator

KX_IPOACT_LOOPEND

See KX_IpoActuator

KX_RANDOMACT_BOOL_CONST

See SCA_RandomActuator

KX_RANDOMACT_BOOL_UNIFORM

See SCA_RandomActuator

KX_RANDOMACT_BOOL_BERNOUILLI

See SCA_RandomActuator

KX_RANDOMACT_INT_CONST

See SCA_RandomActuator

KX_RANDOMACT_INT_UNIFORM

See SCA_RandomActuator

KX_RANDOMACT_INT_POISSON

See SCA_RandomActuator

KX_RANDOMACT_FLOAT_CONST

See SCA_RandomActuator

KX_RANDOMACT_FLOAT_UNIFORM

See SCA_RandomActuator

KX_RANDOMACT_FLOAT_NORMAL

See SCA_RandomActuator

KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL

See SCA_RandomActuator

KX_ACTIONACT_PLAY

See BL_ActionActuator

KX_ACTIONACT_FLIPPER

See BL_ActionActuator

KX_ACTIONACT_LOOPSTOP

See BL_ActionActuator

KX_ACTIONACT_LOOPEND

See BL_ActionActuator

KX_ACTIONACT_PROPERTY

See BL_ActionActuator

KX_SOUNDACT_PLAYSTOP

See KX_SoundActuator

KX_SOUNDACT_PLAYEND

See KX_SoundActuator

KX_SOUNDACT_LOOPSTOP

See KX_SoundActuator

KX_SOUNDACT_LOOPEND

See KX_SoundActuator

KX_SOUNDACT_LOOPBIDIRECTIONAL

See KX_SoundActuator

KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP

See KX_SoundActuator

Generated by Epydoc 2.1 on Thu Feb 1 00:12:33 2007 http://epydoc.sf.net