right mouse button bug?
Blitz3D Forums/Blitz3D Programming/right mouse button bug?
| ||
Hi, I am writing some code that checks to see if left or right mouse button is clicked. The problem is mousehit(2) is not responding. My right mouse button does work anywhere else but in my main code. Anyone know why this is or experienced anything like this. If I simply change mousehit(2) to mouseHit(3), the middle mouse button executes the code properly. Anyway here is a snippet of the code. If cameraMode = 1 ; camera mode to allow picking or interacting with objects If MouseHit (1) DebugLog "left mouse hit" End If If MouseHit (2) ;if rightclick set inventory view DebugLog "right mouse hit" cameraMode = 2;inventory view Return End If rotArea = 35 ; how many pixels to begin rotation If MouseX() < rotArea Then RotateEntity player,EntityPitch(player),EntityYaw(player)+1,EntityRoll(player) If MouseX() > screenWidth - rotArea Then RotateEntity player,EntityPitch(player),EntityYaw(player)-1,EntityRoll(player) If MouseY() < rotArea If EntityPitch(camera) > -70 RotateEntity camera,EntityPitch(camera)-1,EntityYaw(camera),EntityRoll(camera) End If End If If MouseY() > screenHeight - rotArea If EntityPitch(camera) < 70 RotateEntity camera,EntityPitch(camera)+1,EntityYaw(camera),EntityRoll(camera) End If End If End If ; end camera mode 1 If cameraMode = 2 ; inventory Mode If MouseHit(2) Or KeyHit(upkey) Or KeyHit(downkey) Or KeyHit (rightKey) Or KeyHit (leftKey) sketchBookOn = False cameraMode = 1 Return End If sketchBookOn = True End If ; end camera mode 2 p.s. Also there is no where else in the code that mouseHit(2) is called. Strange. |
| ||
You're calling it twice. Mousehit tells you the first time the mouse button is pressed down. Calling it resets the value of the mousehit. To use it more than once in a loop you should assign the value to a variable then reference that.dim mhit(3) repeat for i=1 to 3 mhit(i)=mousehit(i) next if mhit(2) ;do something end if until |
| ||
I think I follow you. What really gets me is that if I change the two references of mousehit(2) to mouseHit(3), it works fine (for the middle button). But some reason the right mouse button is not reacting to this. This code toggles an inventory book. I will try what your saying and get back. |
| ||
its definately something else. If I put the following at the end of my main program:If MouseHit (2) DebugLog "right" UpdateWorld RenderWorld nothing happens when i right click. However the same phenomenon of doing this: If MouseHit (3) DebugLog "right" UpdateWorld RenderWorld returns right in the debuglog if I press the middle button. Now for the strangest part. If I use mousedown instead of mouse hit: If MouseDown (2) DebugLog "right" UpdateWorld RenderWorld I get a bunch of "right" in the debug log when I press the right mouse button down. Im baffled. |
| ||
MouseDown() determines whether a button is currently held down. MouseHit() tells if a button has been pressed since the previous call to MouseHit(). Experiment with this, also trying MouseDown. Graphics 640, 480, 0, 2 While Not KeyDown(1) ; Escape quits Write MouseHit(2) Delay 50 ; so we have time to see what is happening n = n + 1 If n = 75 Print n = 0 End If Wend End |
| ||
thanks guys. Seems Ben was correct. MouseHit(2) was in another function but in the same loop. Thanks to Ross C for finding it in my entire code. |