Blender 3D game engine: SCA_JoystickSensor
Methods:
getAxis getNumHats
getAxisValue getThreshold
getButton isConnected
getButtonValue setAxis
getHat setButton
getIndex setHat
getNumAxes setIndex
getNumButtons setThreshold
Variables:
---------- ----------
Constants:
---------- ----------
Inherited
Methods:
getExecutePriority isPositive
getFrequency isTriggered
getInvert reset
getLevel setExecutePriority
getName setFrequency
getOwner setInvert
getUseNegPulseMode setLevel
getUsePosPulseMode setUseNegPulseMode
isA setUsePosPulseMode



Instance Methods

getAxis

Returns the axis and direction of motion.

Return type:  List  [axis, motion]

axis:
   Type:  integer

1 = x & y axis (left/right & front/back)
2 = throttle paddle

motion:
   Type:  integer

0 = Right Axis
1 = Up Axis
2 = Left Axis
3 = Down Axis

Note:
If Joystick sensor 'All/All Axis Events' toggle button is selected, motion always returns 1

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get axis and motion assigned to this sensor
ax = sen.getAxis()

getAxisValue

getAxisValue()

Returns amount joystick has been moved.

Return type:  list [ x, y, z, zRot]

x is the left/right direction.
Type:  integer. 
Range is 32767 to -32676

y is up/down (front/back).
Type:  integer. 
Range is 32767 to -32767

z is throttle paddle
Type:  integer. 
Range is 32767 to -32767

zRot is the rotation (twist).
Type:  integer. 
Range is 32767 to -32767

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get axis value
amount = sen.getAxisValue()

getButton

getButton()

Returns the button and state (pressed/notpressed) that activates sensor.

Return type:   integer
0 is the trigger.
1 is the back center button.  etc

Note:
If Joystick sensor 'All/All Button Events' toggle button is selected, button always returns 1

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get button and state that activates sensor
dir = sen.getButton()

getButtonValue

getButtonValue()

Returns the button that was used.

Return type:  list [ button]

button:
   Type:  integer
0 is the trigger.
1 is the back center button.  etc

Note:
Returns an empty list when the button is released.

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get button
button = sen.getButtonValue()

getHat

getHat()

Returns the hat and the direction that triggers the sensor.

Return type:  list [ hat, direction]
Blender game engine: joystick hat directions

hat:
Type: integer.

1 or 2

direction
Type: integer.

1 is up
2 is right
4 is down
etc--see image to right

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get hat and direction
hat = sen.getHat()

getIndex

getIndex()

Returns which joystick to use.

Return type:  integer

0 = 1st Joystick
1 = 2nd Joystick

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get joystick being used
jStick = sen.getIndex()

getNumAxes

getNumAxes()

Returns the number of axis.

Return type:  integer

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get number of axis
num = sen.getNumAxes()

getNumButtons

getNumButtons()

Returns the number of buttons.

Return type:  integer

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get number of buttons
num = sen.getNumButtons()

getNumHats

getNumHats()

Returns the number of hats.

Return type:  integer

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get number of hats
num = sen.getNumHats()

getThreshold

getThreshold()

Returns the amount joystick has to move before sensor is triggered.

Return type:  integer

Range:  32767 to -32767

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# get amount joystick has to move
amount = sen.getThreshold()

isConnected

isConnected()

Returns if a joystick is connected to the sensor.

Return type:   Bool

True = found joystick
False = didn't find joystick

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# joystick connected?
jConnect = sen.isConnected()

setAxis

setAxis(axis, motion)

Sets the axis and direction of motion.
axis:
1 = x & y axis (left/right & front/back)
2 = throttle paddle

motion:
0 = Right Axis
1 = Up Axis
2 = Left Axis
3 = Down Axis

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# set left axis to be used
sen.setAxis( 1, 2)

setButton

setButton(button)

Sets the button that activates sensor.

button:
0 is the trigger.
1 is the back center button.
etc

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# set trigger pressed to activates sensor
sen.setButton( 0, 0)

setHat

setHat(hat, direction)

Sets the hat and the direction that triggers the sensor.

hat:
Blender game engine: joystick hat directions
Type:  integer.

   1 or 2
 

direction:
Type: integer.

1 is up
2 is right
4 is down
etc--see image to right

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# set hat and direction
sen.setHat(1, 4)

setIndex

setIndex(jIndex)

jIndex:
  Type:   integer

0 = 1st Joystick
1 = 2nd Joystick

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# use first joystick
sen.setIndex(0)

setThreshold

setThreshold(threshold)

Sets the amount joystick has to move before sensor is triggered.

threshold:
Type:  integer.

Range:  32767 to -32767

Sample Code

# get controller
controller = GameLogic.getCurrentController()

# get sensor named FlightStick
sen = controller.getSensor("FlightStick")

# set amount joystick has to move to trigger sensor
sen.setThreshold(3000)



Instance Methods: Inherited

getFrequency

getFrequency()

Returns the delay between repeated pulses.  

Return Type:  Integer
0 = no delay.

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# get sensor Frequency
pulseFreq = sen.getFrequency()

getInvert

getInvert()

Returns if sensor is set to activate on negative events.

Return Type:  Bool

True = sensor activated on negative events
False = sensor activated on positive events

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# trigger on negative pulse?
trigger = sen.getInvert()

getLevel

getLevel()

The Level button is a part of the State System.

Returns whether or not the level (Lvl) button is active.

Level button activated:
Deactivated mouse sensor is reactivated:
Checks to see if a mouse button is being pressed.
If it is, it sends a pulse to the controller.

Level button not activated:
Deactivated mouse sensor is reactivated:
Doesn't check to see if a mouse button is being pressed.
Doesn't send pulse to the controller.

Return Type:  Bool

1 = True = Level button active.
2 = False = Level button inactive.
Note:
Only works reliably when the sensor is connected to a single state.

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# send pulse when activated by State System?
sendPulse = sen.getLevel()

getUseNegPulseMode

getUseNegPulseMode()

Returns if sensor is set to use negative pulse.

Return Type:  Bool

1 = True = Use negative pulse
2 = False = Don't use negative pulse

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# trigger on negative pulse?
trigger = sen.getUseNegPulseMode()

getUsePosPulseMode

setBlendtime(blendtime)

Returns if sensor is set to use positive pulse.

Return Type:  Bool

1 = True = Use positive pulse
2 = False = Don't use positive pulse

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# trigger on positive pulse?
trigger = sen.getUsePosPulseMode()

isPositive

isPositive()

Returns True when sensor is activated.  False when it is deactivated.

Return Type:   Bool

1 = True = sensor activated
0 = False = sensor deactivated

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# sensor being activated?  Deactivated?
activated = sen.isPositive()

isTriggered

isTriggered()

Returns if sensor has triggered the controller

Return Type:   Bool

1 = True = sensor triggered controller
0 = False = sensor hasn't triggered controller

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# sensor triggered controller?
trigger = sen.isTriggered()

reset

reset()

Resets the sensor to it's initial state.  (ie. just activated)

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# reset the sensor
sen.reset()

setFrequency

setFrequency(freq)

Sets the delay between repeated pulses.  

freq: 
Type is integer.

0 = no delay.

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# set Frequency to no delay
sen.setFrequency(0)

setInvert

setInvert(inv)

Sets if  the sensor is to activate on negative events.

inv: 
Type: Bool.

  1 = True = activate on negative events
  0 = False = activate on positive events

Note:
True, False and 1, 0 work as expected

But
getInvert()
2 = False

setInvert(2)
sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# set to activate on negative events
sen.setInvert(True)

setLevel

setLevel(activate)

The Level button is a part of the State System.

Sets whether or not the level (Lvl) button is active.

Level button activated:
Deactivated mouse sensor is reactivated:
Checks to see if a mouse button is being pressed.
If it is, it sends a pulse to the controller.

Level button not activated:
Deactivated mouse sensor is reactivated:
Doesn't check to see if a mouse button is being pressed.
Doesn't send pulse to the controller.


activate:
Type:  Bool

   1 or True = Level button active.
   0 or False = Level button inactive.

Note:
Only works reliably when the sensor is connected to a single state.

Note:
True, False and 1, 0 work as expected

But
getLevel()
2 = False

setLevel(2)
2 sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named sensor
sen = controller.getSensor("sensor")

# set level detector to True
sen.setLevel(True)

setUseNegPulseMode

setUseNegPulseMode(pulse)

Sets the sensor to use negative pulse mode.

pulse: 
 Type  =  Bool.

1 = True = Use negative pulse mode
0 = False = Use positive pulse mode

Note:
True, False and 1, 0 work as expected

But
getUseNegPulseMode()
2 = False

setUseNegPulseMode(2)
2 sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named MouseOver
sen = controller.getSensor("sensor")

# set to use on negative pulse
sen.setUseNegPulseMode(True)

setUsePosPulseMode

setUsePosPulseMode(pulse)

Sets the sensor to use positive pulse mode.

pulse: 
 Type  =  Bool.

1 = True = Use positive pulse mode
0 = False = Use negative pulse mode

Note:
True, False and 1, 0 work as expected

But
getUsePosPulseMode()
2 = False

setUsePosPulseMode(2)
2 sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get sensor named MouseOver
sen = controller.getSensor("sensor")

# set to use on positive pulse
sen.setUsePosPulseMode(True)



Instance Methods: Inherited

getExecutePriority

getExecutePriority()

Gets the execute priority of the logic brick

Return Type:  integer

Doesn't work:
Crashes Blender

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the actuator named act
act = controller.getActuator("act")

# get brick priority
priority = act.getExecutePriority()

getOwner

getOwner()

Gets the game object that owns the logic brick.

Return Type:  KX_GameObject

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the actuator named act
act = controller.getActuator("act")

# get brick owner
owner = act.getOwner()

setExecutePriority

setExecutePriority(priority)

Sets the execution priority of the logic brick.

priority:
   Type:  integer
0 is first
1 is second
etc.

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the actuator named act
act = controller.getActuator("act")

# set brick priority to be first
act.setExecutePriority(0)





isA

isA(Type)

Checks the Object type.
(KX_GameObject, SCA_ILogicBrick, KX_Scene, etc.)

Type:  String

Return Type:  Bool
1 = True
0 = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the object controller attached to
owner = controller.getOwner()

# is owner a GameObject?
gameObject = owner.isA("KX_GameObject")





getName

getName()

Returns the name of actuator

Return Type:  string

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get a list of the attached actuators 
actList = controller.getActuators()

# loop through the list of actuators
for act in actList:

# look for an actuator named "RocketMotion"
if act.getName() == "RocketMotion":

# use it
GameLogic.addActiveActuator(act, True)

# Done.  Break out of loop
break


Blender 3D
Game Engine
Rapid prototyping for 3D games. Test realtime 3D gameplay without having to compile the game code. 3D game models automatically added.  GLSL shaders. Normal Mapping and Parallax Mapping. All OpenGL Lighting modes. This includes transparencies, animated and reflection mapped textures. Multiple textures and materials. UV mapping. Per-pixel lighting and dynamic lighting.  Uses Bullet Physics. Soft body dynamics. Rigid body dynamics. Collision detection and dynamics simulation. Collision bounds of all types. Car physics engine with full support for vehicle dynamics. (Spring reactions, stiffness, damping, tire friction etc.).