FlushJoy not working...

BlitzMax Forums/BlitzMax Beginners Area/FlushJoy not working...

Ryan Burnside(Posted 2009) [#1]
Hello, I need to flush my joysticks after a level is compleated. The fire button is also the menu confirmation button. It seems that FlushJoy() is not clearing properly...

Is this a known problem?


jkrankie(Posted 2009) [#2]
I noticed this recently too, it's a bit of a pain. a quick:

for local i:int=0 to 15
      if joydown(i)
           'do nothing
      end if
next


does the trick, but it's far from ideal.

Cheers
Charlie


xlsior(Posted 2009) [#3]
A little more efficient, no need to declare an additional variable, plus able to deal with >16 queued commands:

while joydown(i)
' do nothing
wend



Uncle(Posted 2009) [#4]
Glad I saw this topic as I have been using flushjoy today and was wondering what was going on. Unfortunately the solutions above didn't work well for me because if the joystick button is held down it gets stuck in the loop until it is depressed. Ideally the joyhit queue should just be cleared.

On further investigation it appears flushjoy has never been implemented in the freejoy.bmx module. I quickly bunged in this code and it seems to work :

Function FlushJoy(port = 0)
	For Local a:Int = 0 To 15
		For Local b:Int = 0 To 15
			joy_hits[a, b] = 0
		Next
	Next
End Function


This seems to clear the queue.


xlsior(Posted 2009) [#5]
Probably something that should be added to the official module...


Ryan Burnside(Posted 2009) [#6]
Thanks guys!

Function FlushJoy(port = 0)
	For Local a:Int = 0 To 15
		For Local b:Int = 0 To 15
			joy_hits[a, b] = 0
		Next
	Next
End Function

What is port? Doesn't seem to get used. Also I tried calling this for all connected joysticks and it does not appear to work...


Uncle(Posted 2009) [#7]
port was in the original function header, and could be used if required. From what I saw there is an array called joy_hits which stores all the mouse hits. The array is 16 x 16 allowing 16 joysticks with 16 buttons. The routine above clear the whole array (all joysticks all buttons). You could change it to clear only the joystick on "port".

Ryan, did you build the freejoy module before trying? The above seemed to work for me. Perhaps you could post some code where it doesnt work and we can try and find out whats going on. In the meantime you could try the solution in this thread...

http://www.blitzbasic.com/Community/posts.php?topic=82706#932872

Cheers.


Ryan Burnside(Posted 2009) [#8]
Well I didn't want to edit the original modules, I wanted my code to be portable for source code sharing. I added it as a custom function and renamed it. I assume that since I have included the freejoy module the array becomes public?

It is really late here and I will have to look for another bug somewhere else. Because what you said does make sense. I have a feeling now that it might be a problem elsewhere in my code.

Here is my code to catch any joykey press, go to the next part of the game and flush keys. It does not appear to clear the keys. My "AllFlushJoy()" command is exactly like yours.

For Local j:Int = 0 To JoyCount() - 1
	For Local i:Int = 0 To 15
		If JoyDown(i, j)
					
			t.set_timer(10)
			players.clear()
			create_players()
			spark_list.clear()
			AllFlushJoy()
			game_mode = "game"
		EndIf
        Next
Next



Uncle(Posted 2009) [#9]
Just a thought try changing...

If JoyDown(i,j)


to

If JoyHit(i,j)


in your code and see if that fixes it.


Ryan Burnside(Posted 2009) [#10]
Yeah looks like that fixed it. I was thinking that if you cleared the joystick, it would not regester a button hold after the clear until the button was released. But I guess it makes since since the stick is polled each cycle.