Joypad Problems

Archives Forums/BlitzMax Bug Reports/Joypad Problems

MrTAToad(Posted 2008) [#1]
When reading joypads, I have found that even when reading values from non-existant ports, values from the valid port are used instead :



If one joypad is put in, all ports 0 to 8 show when button 1 is pressed, instead of just port 0.


Yan(Posted 2008) [#2]
Still not sure whether it's a bug or not, but it *should at least be documented*...

http://blitzbasic.com/Community/posts.php?topic=60913


This should work...
Graphics 640,480

JoyCount()

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	For loop=0 to 8
		DrawText JoyDown(1, loop), 0, loop * 16
	Next
	
	Flip
EndWhile

??


MrTAToad(Posted 2008) [#3]
Unfortunately adding JoyCount doesn't help.

Its a problem mainly due to the different number of controllers that each OS supports.


Yan(Posted 2008) [#4]
Hmm...That's what I get for not testing code prior to posting. ;o)

The code I posted in the previous thread no longer works either. Looks like something has changed along the way.

However, whilst the FreeJoy commands probably *should* be returning null values for free ports, you should really be using something like...
Graphics 640,480

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	For loop=0 Until JoyCount()
		DrawText JoyDown(1, loop), 0, loop * 16
	Next
	
	Flip
EndWhile
...anyway. Unless there's a reason you *need* to be reading from unused ports?


Its a problem mainly due to the different number of controllers that each OS supports.
Not sure what that means exactly.


MrTAToad(Posted 2008) [#5]
It means the maximum number of joypads each OS can handle is different. This means that aside from initialising the joypad system, JoyCount isn't always useful, and can cause problems.

In addition, the empty commands in FreeMod need filling in - I ceraintly need the FlushJoy function...


Yan(Posted 2008) [#6]
This means that aside from initialising the joypad system, JoyCount isn't always useful, and can cause problems.
Perhaps I'm being particularly dim today, but I'm still not sure exactly what you're getting at. In what way can JoyCount cause problems?


MrTAToad(Posted 2008) [#7]
Its mainly when a joypad is unplugged - there is no way to re-initialise the joypad system to re-detect the number of joypads, which means as non-valid ports return dodgy data there can be... problems...


Yan(Posted 2008) [#8]
Isn't that exactly what JoyCount does?

This...
Strict

Graphics 800, 400, 0

Repeat
	Local joyNum = JoyCount()
	Cls
	
	If joyNum
	  For Local thisPort = 0 Until joyNum
			Local joy$ = JoyName(thisPort) + " on port " + thisPort + " = "
			DrawText joy$, 0, thisPort * 14
			
	    For Local thisButton = 0 To Int(Log(JoyButtonCaps(thisPort)) / Log(2))
	      DrawText JoyDown(thisButton, thisPort), (TextWidth(joy$) + 1) + (thisButton * 24), thisPort * 14
	    Next
	  Next
	Else
		DrawText "No Joypads available", 0, 0
	endif
  
  Flip
Until KeyHit(KEY_ESCAPE) Or AppTerminate()

End
...certainly works fine for me whilst adding and removing joypads.

??


Although I'm still sceptical about your need for null values. ;o)

I agree that free ports probably should return null data, for the sake of tidiness if nothing else.


I'm also a bit curious as to why things have changed as I don't recall FreeJoy being updated, for windows at least, recently.


MrTAToad(Posted 2008) [#9]
It happens, if I remember correctly with Mac, Windows and possibly Linux as well.


Digital Anime(Posted 2008) [#10]
Had no problems with that under Windows, only thing I noticed that JoyCount() is needed in cases where you want to create a game for 2 or more players and only 1 joypad is plugged in.

What happened to me is when only 1 pad is plugged in and press fire to start the game all players reacted to joypad 0 for some reason. When I plugged in all three joypads (3 player game in my case) the game works fine... So in my case I needed JoyCount() to check amount of joystick devices plugged in and update that data in case something changes.