xbox controler read try

Game development specific discussions.
Post Reply
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

xbox controler read try

Post by bluatigro »

i was testing my new xbox controler
only by joyid = 0 i get readings

but does not change the readings when using the controler

is my xbox controler defect or do i something not good

help wanted

error :
joyid does not change on cursor pres

shal i bring it back ?
or has anyone a better idea ?

Code: Select all




#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
  Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif

dim as single a( 8 )
dim as integer joyid = 0 , button , i

do 
  cls
  print
  print "joyid = " ; joyid
  if not getjoystick( joyid , button _
  , a( 0 ) , a( 1 ) , a( 2 ) , a( 3 ) _
  , a( 4 ) , a( 5 ) , a( 6 ) , a( 7 ) ) then
    print "buttons = " ; bin( button , 32 )
    print "button = " ; button
    for i = 0 to 7
      print "a( " ; i ; " ) = " , a( i )
    next i
  else
  end if 
  if multikey( sc_up ) then joyid = ( joyid + 1 ) and 15
  if multikey( sc_down ) then joyid = ( joyid - 1 ) and 15
  sleep 100
loop until inkey = chr( 27 )
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: xbox controler read try

Post by paul doe »

Nothing is wrong with your controller. You need to link to FBGFX for getJoystick() to work (set a screen mode first):

Code: Select all

#include once "fbgfx.bi"

'' Some common ASCII codes
namespace ASCIICode
  const as string _
    KEY_UP => chr( 255, asc( "H" ) ), _
    KEY_DOWN => chr( 255, asc( "P" ) ), _
    KEY_ESC => chr( 27 )
  
  /'
    ...
  '/
end namespace

'' Otherwise getJoystick() won't work
screenRes( 800, 600, 32 )

dim as single a( 8 )
dim as integer joyid = 0 , button , i

dim as string _
  keyPress

do
  screenLock()
    cls()
    print
    print "joyid = " ; joyid
    
    if( not getjoystick( joyid , button , _
      a( 0 ) , a( 1 ) , a( 2 ) , a( 3 ) , _
      a( 4 ) , a( 5 ) , a( 6 ) , a( 7 ) ) ) then
      
      print "buttons = " ; bin( button , 32 )
      print "button = " ; button
      
      for i = 0 to 7
        print "a( " ; i ; " ) = " , a( i )
      next i
    end if
  screenUnlock()
  
  /'
    Use inkey() for this part. Multikey() is way too fast, and
    you need to implement this another way.
  '/
  keyPress => inkey()
  
  if( keyPress = ASCIICode.KEY_UP ) then 
    joyid = ( joyid + 1 ) and 15
  end if
  
  if( keyPress = ASCIICode.KEY_DOWN ) then 
    joyid = ( joyid - 1 ) and 15
  end if
  
  '' This should be enough. More makes the code unresponsive.
  sleep( 10, 1 )
loop until( keyPress = ASCIICode.KEY_ESC )
bluatigro
Posts: 660
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: xbox controler read try

Post by bluatigro »

update :
added xbox consts
changed some code that was not working

are the consts for every game controler the same ?

Code: Select all

#include once "fbgfx.bi"

'' Some common ASCII codes
namespace ASCIICode
  const as string _
    KEY_UP = chr( 255, asc( "H" ) ), _
    KEY_DOWN = chr( 255, asc( "P" ) ), _
    KEY_ESC = chr( 27 )
end namespace

namespace xbox
  const as integer joy_left_x = 0
  const as integer joy_left_y = 1
  const as integer joy_right_y = 3
  const as integer joy_right_x = 4
  const as integer button_a = 1
  const as integer button_b = 2
  const as integer button_x = 4
  const as integer button_y = 8
  const as integer button_left = 16
  const as integer button_right = 32
end namespace

function boolstr( i as ulong , b as ulong ) as string
  if i and b then return "true"
  return "false"
end function

'' Otherwise getJoystick() won't work
screenRes 800, 600, 32 

dim as single ja( 8 )
dim as integer joyid = 0 , jbutton , i

dim as string keyPress 

do
  screenLock()
    cls()
    print
    print "joyid = " ; joyid
    
    if( not getjoystick( joyid , jbutton , _
      ja( 0 ) , ja( 1 ) , ja( 2 ) , ja( 3 ) , _
      ja( 4 ) , ja( 5 ) , ja( 6 ) , ja( 7 ) ) ) then
      
      print "xbox joystick left x = " ; ja( xbox.joy_left_x )
      print "xbox joystick left y = " ; ja( xbox.joy_left_y )
      print "xbox joystick right x = " ; ja( xbox.joy_right_x )
      print "xbox joystick right y = " ; ja( xbox.joy_right_y )
      print "button x =     " ; boolstr( jbutton , xbox.button_x )
      print "button y =     " ; boolstr( jbutton , xbox.button_y )
      print "button a =     " ; boolstr( jbutton , xbox.button_a )
      print "button b =     " ; boolstr( jbutton , xbox.button_b )
      print "button left =  " ; boolstr( jbutton , xbox.button_left )
      print "button right = " ; boolstr( jbutton , xbox.button_right )
      
    end if
  screenUnlock()
  
  
  ''  Use inkey() for this part. Multikey() is way too fast, and
  ''  you need to implement this another way.

  keyPress = inkey()
  
  if( keyPress = ASCIICode.KEY_UP ) then 
    joyid = ( joyid + 1 ) and 15
  end if
  
  if( keyPress = ASCIICode.KEY_DOWN ) then 
    joyid = ( joyid - 1 ) and 15
  end if
  
  '' This should be enough. More makes the code unresponsive.
  sleep( 10, 1 )
loop until( keyPress = ASCIICode.KEY_ESC )

Post Reply