mousedown and mousehit

Blitz3D Forums/Blitz3D Beginners Area/mousedown and mousehit

Santiworld(Posted 2009) [#1]
hi...

i noted than when i use mousehit or mousedown, sometimes, i have problems, if i use 2 lines with mousehit(1), for example, the second time i call that function, don't response correctly...

code example


while not keyhit(1)

if mousehit(1) then "bla bla"

if mousehit(1) then "bla bla 2"

wend

in that case, i need to press many times to detect the "bla bla 2"

i use mousehit() when i wan't to press a 2d booton..


my question is, which is the right way for use mousehit() or mousedown() for uses like menus, or anything....?


Stevie G(Posted 2009) [#2]
If you look at the docs mousehit tells you how many times the mouse button has been hit since it was last called. The second call to mousehit is likely to always be zero.

Define a mousehit variable globally:
Global M_Hit_L


And use like so:
while not keyhit(1)
  M_Hit_L  = mousehit(1)

  if M_Hit_L "bla bla"
  if M_Hit_L "bla bla 2"

wend



Kryzon(Posted 2009) [#3]
Not only should you use that "value registering" approach for MouseHits but pretty much any other key press:
CTRL = KeyHit(29)
SPACE = KeyHit(57)
[...]

That'll keep your IF statements from doing something they shouldn't.

Also you may notice that when you apply a simple "Right-Key moves right, Left-Key moves left" scheme, you'll notice that one of the sides always has a priority over the other (when you hold 1 key first and the hold the other, one of them will have a priority over the other). To do that you simply check to see if they are not being both pressed:
If KEY_LEFT = 1 and KEY_RIGHT = 0 Then ;move left

If KEY_RIGHT = 1 And KEY_LEFT = 0 Then ;move right



Santiworld(Posted 2009) [#4]
thanks!...

for some reason, i haven't read the help of that funciton...

is very helpfull the keys info too..