Joy?(port) problem?

Blitz3D Forums/Blitz3D Programming/Joy?(port) problem?

jeffmorris(Posted 2006) [#1]
When using joystick commands, I can use the optional port number to have a program act on one joystick instead of other joystick. I think there is a problem - connecting and disconnecting joysticks causes the joystick commands not to work properly. For example, I have MS Force Feedback joystick on joy?(0) and Logitech Driving Force Pro wheel/pedal set on joy?(1). If I disconnect the joystick from USB port, the joystick commands don't work because they expect two joysticks to be connected. How do I have a program check how many joysticks are connected to the USB ports and act on them?

If one joystick then use joy?() commands
If two joysticks then use joy?(0) and joy?(1) commands

Joy?() = any joystick commands like joyx() and joyy().


kevin8084(Posted 2006) [#2]
Have you tried using JoyType() to force the program to check for the joysticks again?


jeffmorris(Posted 2006) [#3]
I tried this code and I think that it worked.

If JoyType(0) Then stick=0
If JoyType(1) Then stick=1
If JoyType(2) Then stick=2
If JoyType(3) Then stick=3
While Not KeyDown(1)
 If JoyHit(13,stick) Then gear=gear-1:If gear<-1 Then gear=-1
 If JoyHit(14,stick) Then gear=gear+1:If gear>1 Then gear=1
 If JoyHit(3,stick) Then gear=gear-1:If gear<-1 Then gear=-1
 If JoyHit(4,stick) Then gear=gear+1:If gear>1 Then gear=1

 If gear=-1 Then gearstring="Reverse"
 If gear=0 Then gearstring="Neutral"
 If gear=1 Then gearstring="Drive"
 EntityParent camera02,camera01
 If JoyY(stick) < -0.05
  If gear=1
   speed=speed+0.005
   If speed>2 Then speed=2
   MoveEntity camera01,0,0,speed
  End If
  If gear=-1
   speed=speed-0.005
   If speed<-0.5 Then speed=-0.5
   MoveEntity camera01,0,0,speed
  EndIf
 End If
 If JoyY(stick) > 0.05
  speed=speed-0.01
  If speed<0 Then speed=0
  speed=speed*0.99
  MoveEntity camera01,0,0,speed
 End If
 If JoyY(stick) > -0.05 And JoyY(stick) < 0.05
  speed=speed*0.99
  MoveEntity camera01,0,0,speed
 End If	
 If JoyX(stick) < -0.05 And speed>0
  steer=-JoyX(stick)
  If steer>1 Then steer=1
  TurnEntity camera01,0,steer,0
 End If
 If JoyX(stick) > 0.05 And speed>0
  steer=-JoyX(stick)
  If steer<-1 Then steer=-1
  TurnEntity camera01,0,steer,0
 End If
 If JoyX(stick) < -0.05 And speed<0
  steer=JoyX(stick)
  If steer<-1 Then steer=-1
  TurnEntity camera01,0,steer,0
 End If
 If JoyX(stick) > 0.05 And speed<0
  steer=JoyX(stick)
  If steer>1 Then steer=1
  TurnEntity camera01,0,steer,0
 End If
 If JoyX(stick) > -0.05 And JoyX(stick) < 0.05 Then steer=0