Skip to content

Commit c1c1d46

Browse files
committed
fixed button number crash
1 parent 73702f7 commit c1c1d46

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

joystick.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ def getAction(self):
2929
try:
3030
xAx = 0
3131
yAx = 0
32+
buttonCount = self.myJoystick.get_numbuttons()
3233

3334
# sometimes 2 axis, sometimes 6, wtf?!
3435
if self.myJoystick.get_numaxes() == 2:
3536
xAx = 0
3637
yAx = 1
38+
elif self.myJoystick.get_numaxes() == 3:
39+
xAx = 0
40+
yAx = 1
3741
else:
3842
xAx = 3
3943
yAx = 4
@@ -50,11 +54,12 @@ def getAction(self):
5054
action = "speedUp"
5155
elif self.myJoystick.get_button(1) and self.joyButtonDown is False: # speed down
5256
action = "speedDown"
53-
elif (self.myJoystick.get_button(9) and self.joyButtonDown is False)\
54-
or (self.myJoystick.get_button(3) and self.joyButtonDown is False): # (re)start
57+
elif (buttonCount > 9 and self.myJoystick.get_button(9) and self.joyButtonDown is False)\
58+
or (buttonCount > 3 and self.myJoystick.get_button(3) and self.joyButtonDown is False): # (re)start
5559
action = "restart"
56-
elif self.myJoystick.get_button(8) and self.joyButtonDown is False:
60+
elif buttonCount > 8 and self.myJoystick.get_button(8) and self.joyButtonDown is False:
5761
action = 'quit'
62+
5863
#else:
5964
# make sure NO button is down for reset
6065
someJoyButtonDown = False

0 commit comments

Comments
 (0)