How does JoyHit() Work?

BlitzMax Forums/BlitzMax Programming/How does JoyHit() Work?

Matt McFarland(Posted 2006) [#1]
It counts how many times you hit the button? Apparently it just sits at 0 the whole time (yes I made sure the port was correct)

/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
|Function JoyHit( button,port=0 )                            | 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
|Returns:         Number of times button has been hit.       |
|Description:     Check for a joystick button press.         |
|Information:     The returned value represents the number   |
|                 of the times button has been hit since the |
|                 last call to JoyHit with the same key.     |
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/

Since the last call to joyhit with the same key.. What does that mean?!?


Yan(Posted 2006) [#2]
It means you have to call it at least twice (like all the other 'hit' commands) for it to work...
Repeat
	Print MilliSecs()
Until JoyHit(0)



Matt McFarland(Posted 2006) [#3]
Hmm I called it twice but it didnt do anything?


Dreamora(Posted 2006) [#4]
Is your joystick recognized correctly? (to test that, you might go to showcase board and search for gridwars and switch its controll to joy)

btw: You aren't using that within a Canvas, aren't you?


Matt McFarland(Posted 2006) [#5]
Uhh I can use the JoyDown() Function and the JoyX and Y Functions just fine!! at any rate I did a workaround but I'd still REALLY like to see someone use JoyHit() Go ahead and try it yourself! :D

The game I was working on now has gamepad control..

http://www.blitzmax.com/Community/posts.php?topic=58022


skidracer(Posted 2006) [#6]
GeoffTheGyratingGiraffe's simple test works fine for me.


Matt McFarland(Posted 2006) [#7]
I dont understand it, it repeats until you hit the button and prints the millisecs()?

The documentation says it returns how many times the button has been hit

it says Until JoyHit(0)

What does that mean?

Until JoyHit() = what? Isnt JoyHit returning something?

Why doesnt this work:

Repeat

    If JoyHit(0) then print "Joy Hit"

Until Keyhit(Key_ESCAPE



undomiel(Posted 2006) [#8]
Wouldn't it be Until JoyHit(0) equals something other than 0?

That's my understanding of what I'm reading here. I just tested out your bit of code with my joystick here and it worked just fine. Looks like it might be a bug then?


Grey Alien(Posted 2006) [#9]
works here too although only with one button (button 0).


Matt McFarland(Posted 2006) [#10]
Gery: What works? the until loop or the IF joyhit??


Grey Alien(Posted 2006) [#11]
this one
Repeat

    If JoyHit(0) then print "Joy Hit"

Until Keyhit(Key_ESCAPE



undomiel(Posted 2006) [#12]
Both of them worked for me.


Matt McFarland(Posted 2006) [#13]
Hmm that's funny JoyHit(0) doesnt work for me at all but JoyDown(0) does..


Yan(Posted 2006) [#14]
There's a bug with the JoyHit() command, but I'm not sure if it's causing your problems. The button and port parameters are transposed.

This should work...
[edit]
Doh!...No it won't, you'll have to use this fix if you can compile modules and want to add it yourself.
[/edit]
'You need the fix to run this properly!
Strict

Graphics 800, 600, 0

If Not(JoyCount()) Then RuntimeError "No joysticks found!"

Local y = -12

Repeat
  For Local thisPort = 0 Until JoyCount()
    For Local thisButton = 0 To Int(Log(JoyButtonCaps(thisPort)) / Log(2))
      If JoyHit(thisButton, thisPort)
        y :+ 12
        
        If y > (GraphicsHeight() -12)
          y = 0
          Cls
        EndIf
	DrawText "Button " + thisButton + " on Port " + thisPort + " was hit", 0, y
      EndIf
    Next
  Next
  
  Flip
Until KeyHit(KEY_ESCAPE) Or AppTerminate()

End