Using Multiple Joysticks in Purebasic

Just starting out? Need help? Post your questions and find answers here.
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Using Multiple Joysticks in Purebasic

Post by Chirantha »

Hi,

This is the procedure I want to follow. I want to go through all the joysticks available on the system and check if button 1 and 3 are pressed. If it is, I want to start using that joystick.

The problem is Purebasic only allows me to use one joystick. I tried a userlib but its example is broken.. it keeps saying Invalid memory access. And tried another method I found on the forum but that is outdated code :(

Can anyone help?

Thanks
Fred
Administrator
Administrator
Posts: 14215
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

We added multiple joystick support in 4.30, so we the beta will be out, you could use it.
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Post by Chirantha »

Fred wrote:We added multiple joystick support in 4.30, so we the beta will be out, you could use it.
When will it be out? :( I have a deadline to meet for my project.
Fred
Administrator
Administrator
Posts: 14215
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

We have no date for now. If you have a deadline, just use API then (there is some examples on the forums IIRC).
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Post by Chirantha »

Well :( I look at the tips and tricks section but the code and the code on most user libs are outdated.. I'm getting weird errors when I try to complile.

Can someone help me get those codes to work? I'm so close yet so far :(

http://www.purebasic.fr/english/viewtop ... =joysticks
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4828
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

it would be helpful to know wich PB-Version you are using.

also, have a look on www.purearea.net
you can find the Code-Archive and the PBOSL there.
both provide sources.
oh... and have a nice day.
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Post by Chirantha »

I'm using 4.20. And I got two joystick libs from purearea. None of them
seem to work at 100%.
User avatar
Rings
Moderator
Moderator
Posts: 1402
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

SPAMINATOR NR.1
User avatar
djes
Addict
Addict
Posts: 1804
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Your search is flawed, try searching for joystick in the forum. With this code you can work with multiple joysticks by changing the #JOYSTICKID1 constant. All values possible are in the JOYINFOEX structure

Code: Select all

joy_an = joyGetNumDevs_()
joyCaps.JOYCAPS

For u=0 To joy_an ;how many joysticks in the system?
  joyGetDevCaps_(u, joyCaps, SizeOf(JOYCAPS))
  Debug "Joystick "+Str(u)
  Debug joyCaps\szPname
Next u

If joySetCapture_(WindowID(1), #JOYSTICKID1, #Null, #False) = #JOYERR_NOERROR ;should be remplaced by initjoystick() in fullscreen
  If joyGetDevCaps_(#JOYSTICKID1, joyCaps, SizeOf(JOYCAPS)) = #JOYERR_NOERROR
    JoyXamp.l = joyCaps\wXmax - joyCaps\wXmin ;amplitude du mouvement du joystick en X
    JoyYamp.l = joyCaps\wYmax - joyCaps\wYmin
    ; done
  Else
    Debug "Joystick error"
  EndIf
EndIf

joyInfoEx.JOYINFOEX
joyInfoEx\dwFlags = #JOY_RETURNALL
joyInfoEx\dwSize = SizeOf(JOYINFOEX)

;---
joyGetPosEx_(#JOYSTICKID1, joyInfoEx.JOYINFOEX)

;---
if (joyInfoEx\dwButtons&1) And joystick_switch
   blah bla
endif
x = joyInfoEx\dwXpos ;...
Post Reply