cant do 2 things with mousehit()

Blitz3D Forums/Blitz3D Programming/cant do 2 things with mousehit()

slenkar(Posted 2004) [#1]
If I check mousehit(1) 2 or 3 twice in the program the second time will not register.

For example if I click the mouse on a menu button it will not register because the same mouse button is checked in a different place in the program for doing a camerapick

strange thing is, if I check for mousedown() instead (the second time) it works OK


Ross C(Posted 2004) [#2]
Yeah, i dunno how long it takes for mousehit() to clear it's self. Best thing is to use mousedown() with a timer, or use:


If MouseHit(1) then

     ;Check everything related to mousehit()

End if



OR, set a variable and check that:


while not keyhit(1)

   mouse_hit = 0

   if mousehit(1) then
       mouse_hit = 1
   end if

   if mouse_hit = 1 then
      ;check menu
   end if

   if mouse_hit = 1 then
      ;check buttons
   end if

wend


:o)


puki(Posted 2004) [#3]
What about if you use FlushMouse somewhere in between? I'm just clutching at straws there - you may have tried it already.


slenkar(Posted 2004) [#4]
Ill try that Ross thanks,

I tried flushmouse but it made nothing register at all, maybe I used it in the wrong place

edit-tried it and it works a treat, great thanks


Gabriel(Posted 2004) [#5]
This is correct behaviour, and keyhit works the same way. They return the number of times they have been pressed since the last time you checked. Ross's second method is the generally accepted way to deal with this, particularly for bigger programs.

You're right, mousedown() won't clash with it, neither will KeyDown()


Jeremy Alessi(Posted 2004) [#6]
Once per loop just store the mousehits. It's cleaner this way.

Function UpdateLogic()
   
   mb1pressed = 0
   mb1pressed = MouseHit(1)

End Function


Then throughout the code the rest of your loop just check for mb1pressed. This also makes your life easier for recording demos etc... to get all input in one spot in your code.


poopla(Posted 2004) [#7]
Or why not store the mouse input in a variable and reference that?

Edit: beat me to it.


Luke.H(Posted 2004) [#8]
mousehit cheaks if the mouse was pressed since the last time mousehit was called.

So it should only be called once a loop.