Using 2 seperate MouseHits?

BlitzMax Forums/BlitzMax Beginners Area/Using 2 seperate MouseHits?

Amon(Posted 2007) [#1]
I am in the process of finalising my map editor (non MaxGUI).

On my PC I've been unable to have 2 seperate Mousehits doing different things.

I've made a small test program to show you what I mean.

SuperStrict

Graphics 800, 600

Global num:Int = 0
Global tick:Int = 0

While Not KeyHit(KEY_ESCAPE)
	
	Cls
		If MouseX() > 0 and MouseX() < 800
			If MouseY() > 0 and MouseY() < 600
				
				If MouseHit(MOUSE_LEFT) 
					num:+1
				EndIf
				
				If MouseHit(MOUSE_LEFT) 
					tick:+1
				End If
			
			End If
		End If
	
		DrawText "Num = " + num, 0, 0
		DrawText "Tick = " + tick, 0, 15
	
	Flip
	
Wend


When I run the following on my PC num increases with every mousehit but tick doesn't.

Why?

Can I not use 2 seperate mousehits doing different things?


Amon(Posted 2007) [#2]
FIXED

SuperStrict

Graphics 800, 600

Global num:Int = 0
Global tick:Int = 0

While Not KeyHit(KEY_ESCAPE)
	
	Cls
		Local MHL:Int = MouseHit(MOUSE_LEFT) 
		If MouseX() > 0 and MouseX() < 800
			If MouseY() > 0 and MouseY() < 600
				
				If MHL
					num:+1
				EndIf
				
				If MHL
					tick:+1
				End If
			
			End If
		End If
	
		DrawText "Num = " + num, 0, 0
		DrawText "Tick = " + tick, 0, 15
	
	Flip
	
Wend


Don't know why it doesn't work using the method in the first post but this method here works.


Perturbatio(Posted 2007) [#3]
from the docs:
The returned value represents the number of the times button has been clicked since the last call to MouseHit with the same button.



It is working, the problem is it takes less than a millisecond to call the second mousehit, during which time you would be unlikely to click the mouse (insert delay 10 between the two If MouseHit statements to see this.


Amon(Posted 2007) [#4]
That makes sense. Thanks. :)


ima747(Posted 2007) [#5]
MouseHit becomes active when the mouse is clicked (down and up I believe to count) and it's value is cleared when you call MouseHit(), not at the end of your loop (because MouseHit() doesn't know when it's being called, in a loop, at the start of your program, it doesn't care) so it always goes back to 0 after you check, untill the next full click of the mouse. Your fix is the kind of thing that you will need to do to test the value twice, since the first check will clear the value, and like Perturbatio said, it's un-likely someone can click fast enough to get MouseHit() to activate twice in one loop.

Polled input can be anoying sometimes, but it gives you control.