Joystick - activate button inputs

Hi everyone!

Currently i have problem with the last 2 lines of this code. can someone tell me how i can make the player jump? Button 0 is the triangle button on Playstation 2 controller.


from bge import logic


cont = logic.getCurrentController()
player = cont.owner


#Playstation controller
#0 = Dreieck, 1 = Kreis, 2 = Kreuz, 3 = Box , 
#4 = L2,5 = R2
#6 = L1, 7 = R1
#8 = select, 9 = Start


#0:None
#1:Up
#2:Right
#4:Down
#8:Left
#3:Up - Right
#6:Down - Right
#12:Down - Left
#9:Up - Left


joystick = cont.sensors['Joystick']
button = cont.sensors['Button']
hat = cont.sensors['Hat']


#####JOY STICK######
axis = joystick.axisValues
ax0 = axis[0]
ax1 = axis[1]


#####BUTTONS######
but = button.button
bu0 = button.getButtonStatus(0)




player.applyMovement([ax0 * 0.00001,ax1 * -0.00001, 0], True)


if bu0.positive:
    cont.activate("Jump")

well i solved it!



from bge import logic


cont = logic.getCurrentController()
own = cont.owner


#Playstation controller
#0 = Dreieck, 1 = Kreis, 2 = Kreuz, 3 = Box , 
#4 = L2,5 = R2
#6 = L1, 7 = R1
#8 = select, 9 = Start


#0:None
#1:Up
#2:Right
#4:Down
#8:Left
#3:Up - Right
#6:Down - Right
#12:Down - Left
#9:Up - Left


joy = cont.sensors['Joystick']
ground = cont.sensors['ground']


joy.index = 0


#####Axes######
axis = joy.axisValues
ax0 = axis[0]
ax1 = axis[1]


#####BUTTONS######
joy.button = 0
butlist = joy.getButtonActiveList()
bu0 = joy.getButtonStatus(0)
bu1 = joy.getButtonStatus(1)
bu2 = joy.getButtonStatus(2)


own.applyMovement([ax0 * 0.00001,ax1 * -0.00001, 0], True)


if bu2 == True and own['ground'] == True:
    cont.activate('Jump')
    own['ground'] = False
else:         
    cont.deactivate('Jump')
    
if ground.positive:
    own['ground'] = True

I would reduce the length of the variable names to a single character ;).

hey i came up with a way that might be easier… i think :rolleyes:… i just define the input as they are to be imported under “game logic”…
then made a saprite script to manage its useage… feel free to use as you please…

Joystick

def VersionCheck():
try:
import Mathutils
VERSION = 2.49
except:
import mathutils
VERSION = 2.5
return VERSION

VERSION = VersionCheck()

if VERSION == 2.49:
GameLogic.VERSION = VersionCheck()
import GameLogic as g
elif VERSION == 2.5:
import bge
g = bge.logic

cont = g.getCurrentController()
scene = g.getCurrentScene()
own = cont.owner

#Get_Sensor_Name
joystick = cont.sensors[“joystick”]

#Read_Axis
g.Left_X = joystick.axisValues[0] #Left/Right
g.Left_Y = joystick.axisValues[1] #Up/Down

g.Right_Y = joystick.axisValues[3] #Up/Down
g.Right_X = joystick.axisValues[4] #Left/Right

g.trigger = joystick.axisValues[2] #Left/Right_Trigger

#Read_Buttons
g.A = joystick.getButtonStatus(0)
g.B = joystick.getButtonStatus(1)
g.X = joystick.getButtonStatus(2)
g.Y = joystick.getButtonStatus(3)
g.L_Bumper = joystick.getButtonStatus(4)
g.R_Bumper = joystick.getButtonStatus(5)
g.Back = joystick.getButtonStatus(6)
g.Start = joystick.getButtonStatus(7)
g.LTS = joystick.getButtonStatus(8)
g.RTS = joystick.getButtonStatus(9)

g.Left_Trigger = g.trigger > 10000
g.Right_Trigger = g.trigger < -10000

g.center = joystick.hatValues[0]

#Buttons
##A_Button
if g.A == True:
g.A_buttonTimer += 0.5
else:
g.A_buttonTimer = 0.0

if g.A_buttonTimer > 0.1 and g.A_buttonTimer < 0.9:
g.A_buttonStatus = ‘pressed’

elif g.A_buttonTimer > 0.9:
g.A_buttonStatus = ‘held’

elif g.A_buttonTimer == 0.0:
g.A_buttonStatus = ‘_’

##B_Button
if g.B == True:
g.B_buttonTimer += 0.5
else:
g.B_buttonTimer = 0.0

if g.B_buttonTimer > 0.1 and g.B_buttonTimer < 0.9:
g.B_buttonStatus = ‘pressed’

elif g.B_buttonTimer > 0.9:
g.B_buttonStatus = ‘held’

elif g.B_buttonTimer == 0.0:
g.B_buttonStatus = ‘_’

##X_Button
if g.X == True:
g.X_buttonTimer += 0.5
else:
g.X_buttonTimer = 0.0

if g.X_buttonTimer > 0.1 and g.X_buttonTimer < 0.9:
g.X_buttonStatus = ‘pressed’

elif g.X_buttonTimer > 0.9:
g.X_buttonStatus = ‘held’

elif g.X_buttonTimer == 0.0:
g.X_buttonStatus = ‘_’

##Y_Button
if g.Y == True:
g.Y_buttonTimer += 0.5
else:
g.Y_buttonTimer = 0.0

if g.Y_buttonTimer > 0.1 and g.Y_buttonTimer < 0.9:
g.Y_buttonStatus = ‘pressed’

elif g.Y_buttonTimer > 0.9:
g.Y_buttonStatus = ‘held’

elif g.Y_buttonTimer == 0.0:
g.Y_buttonStatus = ‘_’

##L_Button
if g.L_Bumper == True:
g.L_buttonTimer += 0.5
else:
g.L_buttonTimer = 0.0

if g.L_buttonTimer > 0.1 and g.L_buttonTimer < 0.9:
g.L_buttonStatus = ‘pressed’

elif g.L_buttonTimer > 0.9:
g.L_buttonStatus = ‘held’

elif g.L_buttonTimer == 0.0:
g.L_buttonStatus = ‘_’

##R_Button
if g.R_Bumper == True:
g.R_buttonTimer += 0.5
else:
g.R_buttonTimer = 0.0

if g.R_buttonTimer > 0.1 and g.R_buttonTimer < 0.9:
g.R_buttonStatus = ‘pressed’

elif g.R_buttonTimer > 0.9:
g.R_buttonStatus = ‘held’

elif g.R_buttonTimer == 0.0:
g.R_buttonStatus = ‘_’

##Back_Button
if g.Back == True:
g.Back_buttonTimer += 0.5
else:
g.Back_buttonTimer = 0.0

if g.Back_buttonTimer > 0.1 and g.Back_buttonTimer < 0.9:
g.Back_buttonStatus = ‘pressed’

elif g.Back_buttonTimer > 0.9:
g.Back_buttonStatus = ‘held’

elif g.Back_buttonTimer == 0.0:
g.Back_buttonStatus = ‘_’

##Start_Button
if g.Start == True:
g.Start_buttonTimer += 0.5
else:
g.Start_buttonTimer = 0.0

if g.Start_buttonTimer > 0.1 and g.Start_buttonTimer < 0.9:
g.Start_buttonStatus = ‘pressed’

elif g.Start_buttonTimer > 0.9:
g.Start_buttonStatus = ‘held’

elif g.Start_buttonTimer == 0.0:
g.Start_buttonStatus = ‘_’

##LTS_Button
if g.LTS == True:
g.LTS_buttonTimer += 0.5
else:
g.LTS_buttonTimer = 0.0

if g.LTS_buttonTimer > 0.1 and g.LTS_buttonTimer < 0.9:
g.LTS_buttonStatus = ‘pressed’

elif g.LTS_buttonTimer > 0.9:
g.LTS_buttonStatus = ‘held’

elif g.LTS_buttonTimer == 0.0:
g.LTS_buttonStatus = ‘_’

##RTS_Button
if g.RTS == True:
g.RTS_buttonTimer += 0.5
else:
g.RTS_buttonTimer = 0.0

if g.RTS_buttonTimer > 0.1 and g.RTS_buttonTimer < 0.9:
g.RTS_buttonStatus = ‘pressed’

elif g.RTS_buttonTimer > 0.9:
g.RTS_buttonStatus = ‘held’

elif g.RTS_buttonTimer == 0.0:
g.RTS_buttonStatus = ‘_’

##Left_Trigger
if g.Left_Trigger == True:
g.Left_TriggerTimer += 0.5
else:
g.Left_TriggerTimer = 0.0

if g.Left_TriggerTimer > 0.1 and g.Left_TriggerTimer < 0.9:
g.Left_TriggerStatus = ‘pressed’

elif g.Left_TriggerTimer > 0.9:
g.Left_TriggerStatus = ‘held’

elif g.Left_TriggerTimer == 0.0:
g.Left_TriggerStatus = ‘_’

##Right_Trigger
if g.Right_Trigger == True:
g.Right_TriggerTimer += 0.5
else:
g.Right_TriggerTimer = 0.0

if g.Right_TriggerTimer > 0.1 and g.Right_TriggerTimer < 0.9:
g.Right_TriggerStatus = ‘pressed’

elif g.Right_TriggerTimer > 0.9:
g.Right_TriggerStatus = ‘held’

elif g.Right_TriggerTimer == 0.0:
g.Right_TriggerStatus = ‘_’

#D-PAD
if g.center == 1:
g.UP = True

if g.center == 4:
g.DOWN = True

if g.center == 8:
g.LEFT = True

if g.center == 2:
g.RIGHT = True

if g.center == 0:
g.UP = False
g.DOWN = False
g.LEFT = False
g.RIGHT = False

##UP
if g.UP == True:
g.upTimer += 0.5
else:
g.upTimer = 0.0

if g.upTimer > 0.1 and g.upTimer < 0.9:
g.up_hatStatus = ‘up_pressed’

elif g.upTimer > 0.9:
g.up_hatStatus = ‘up_held’

elif g.upTimer == 0.0:
g.up_hatStatus = ‘’

##DOWN
if g.DOWN == True:
g.downTimer += 0.5
else:
g.downTimer = 0.0

if g.downTimer > 0.1 and g.downTimer < 0.9:
g.down_hatStatus = ‘down_pressed’

elif g.downTimer > 0.9:
g.down_hatStatus = ‘down_held’

elif g.downTimer == 0.0:
g.down_hatStatus = ‘’

##LEFT
if g.LEFT == True:
g.leftTimer += 0.5
else:
g.leftTimer = 0.0

if g.leftTimer > 0.1 and g.leftTimer < 0.9:
g.left_hatStatus = ‘left_pressed’

elif g.leftTimer > 0.9:
g.left_hatStatus = ‘left_held’

elif g.leftTimer == 0.0:
g.left_hatStatus = ‘’

##RIGHT
if g.RIGHT == True:
g.rightTimer += 0.5
else:
g.rightTimer = 0.0

if g.rightTimer > 0.1 and g.rightTimer < 0.9:
g.right_hatStatus = ‘right_pressed’

elif g.rightTimer > 0.9:
g.right_hatStatus = ‘right_held’

elif g.rightTimer == 0.0:
g.right_hatStatus = ‘’

Commands

######Joystick_Controls_Script######

by_Quniton_‘Adamsky225’_London

############################
def VersionCheck():
try:
import Mathutils
VERSION = 2.49
except:
import mathutils
VERSION = 2.7
return VERSION

VERSION = VersionCheck()

if VERSION == 2.49:
GameLogic.VERSION = VersionCheck()
import GameLogic as g
elif VERSION == 2.7:
import bge
g = bge.logic

cont = g.getCurrentController()
scene = g.getCurrentScene()
own = cont.owner

targets = scene.objects

rate = 10.0 #max ~movement speed

#get TargetsCam
up = targets[“OBforward”]
down = targets[“OBback.001”]
left = targets[“OBleft.001”]
up_left = targets[“OBforward_left”]
down_left = targets[“OBback_left”]
right = targets[“OBright.001”]
up_right = targets[“OBforward_right”]
down_right = targets[“OBback_right”]
Cam = targets[“OBCam”]

#Get_Sensors
grounded = cont.sensors[“Ground”]

#Get_Actuators
tracker = cont.actuators[“Tracker”]

#Finders
##Grounded
if grounded.positive:
g.status = ‘grounded’
g.playerStatus = ‘idle’
else:
g.playerStatus = ‘fall’
g.status = ‘airbound’

own[‘prop’] = g.disable

#Analog
##Action(Run)
if g.status == ‘grounded’ and g.disable == False:
own.setLinearVelocity([0,g.yPos,g.zPos], True)
###Forwards
if g.Left_Y > 6.5 and g.lockon == False:
g.playerStatus = ‘run’
tracker.object = down
cont.activate(tracker)
g.yPos = -7.0

###Backwards
elif g.Left_Y &lt; -7.5 and g.lockon == False:
    g.playerStatus = 'run'
    tracker.object = up
    cont.activate(tracker)
    g.yPos = -7.0

###Left
elif g.Left_X &lt; -6.5 and g.lockon == False:
    g.playerStatus = 'run'
    tracker.object = left
    cont.activate(tracker)
    g.yPos = -7.0

###Right
elif g.Left_X &gt; 7.5 and g.lockon == False:
    g.playerStatus = 'run'
    tracker.object = right
    cont.activate(tracker)
    g.yPos = -7.0
else:
    g.playerStatus = 'idle'
    cont.deactivate(tracker)
    g.yPos = 0

#Button
##Grounded
if g.status == ‘grounded’ and g.disable == False:
###Button(A)
#Jumping
if g.A_buttonStatus == ‘pressed’:
g.zPos = 10 #Jumping speed
g.jump = True
else:
g.zPos = grounded.hitPosition[2] - 0.1
g.jump = False

###Button(B)
if g.B_buttonStatus == 'pressed':
    g.pick_Timer = 100

if g.pick_Timer &gt; 1 and g.pick_Timer &lt; 100 and g.near == 'item':
    g.disable = True
    g.pickup = True

if g.B_buttonStatus == 'pressed' and g.near == 'box':
    g.pick_Timer = 100

if g.pick_Timer &gt; 1 and g.pick_Timer &lt; 100 and g.near == 'box':
    g.disable = True
    g.pickup = True

###Button(X)
if g.X_buttonStatus == 'pressed' and g.near == 'item':
    g.weaponUse_Timer = 500

###Button(Y)
if g.Y_buttonStatus == 'pressed':
    g.blank = ''

###Button(LB)
if g.LB_buttonStatus == 'pressed':
    g.blank = ''

###Button(RB)
if g.R_buttonStatus == 'held' and g.X_buttonStatus == 'pressed' and g.dash_Timer == 0:
    g.dash_Timer = 45

if g.dash_Timer &gt; 10 and g.dash_Timer &lt; 45:
    g.disable = True
    g.dash = True
    g.yPos = -13

###Button(LTB)
if g.LTB_buttonStatus == 'pressed':
    g.blank = ''

###Button(RTB)
if g.RTB_buttonStatus == 'pressed':
    g.blank = ''

thanks knight

i wonder how to use it, could you explain to me how should i plug it to the logic brick?