GLBasic forum

Main forum => GLBasic - en => Topic started by: Ozden79 on 2010-Jan-29

Title: MOUSESTATE sometimes causes trouble!
Post by: Ozden79 on 2010-Jan-29
Hello There,

When I use MOUSESTATE to get the click state of the mouse button to see whether a menu item is clicked, I sometimes encounter that MouseButton1 always returning 1 after I click only one time to the mouse button. I use local variables to get those values. Is there anything else I need to do to reset the MOUSESTATE or something?

By the way, this seems to be occuring on Windows 7 PC and not on IPod Touch that I tested.

Özden
Title: Re: MOUSESTATE sometimes causes trouble!
Post by: Moru on 2010-Jan-29
Do you have a little bit of code please?

The usual misstake is that you check the mousebutton but don't wait until the button has been released after the press. See the keyhit library for some tips.
Title: Re: MOUSESTATE sometimes causes trouble!
Post by: Ozden79 on 2010-Jan-29
Hi There,

I already experimented that if the mouse button is down, MOUSESTATE always return 1 and not for one time. That's ok and what I see happens after I release the mouse button and till I click once more, it assumes that the mousebutton is still down.

Thanks for the reply though...

Özden
Title: Re: MOUSESTATE sometimes causes trouble!
Post by: Hemlos on 2010-Jan-29
1. for mousestate: call this command at the top of your main loop....it can act wierd if other things are processed first.

2. have you tried mouseaxes(3,4) command instead ?

3. It is possible your mouse is broken.
Title: Re: MOUSESTATE sometimes causes trouble!
Post by: Ozden79 on 2010-Jan-29
Option 3 is not possible as I've multiple mouses that I tested and also no windows app does reproduce this behavior. With Option 1, you mean without drawing anything, etc. into the screen I assume? I'll also give a shot to the MOUSEAXIS function.

Thanks a lot...

Özden
Title: Re: MOUSESTATE sometimes causes trouble!
Post by: Hemlos on 2010-Jan-30
With Option 1, you mean without drawing anything, etc. into the screen I assume?

Yes, yet more specifically, before all routines.

example:

global something
while true
mousestate
makesounds()
drawstuff()
showscreen
wend

With mouseaxis you might want to consider this to be used the same way as mousestate...top of your loops.

Title: Re: MOUSESTATE sometimes causes trouble!
Post by: Moru on 2010-Jan-30
Even if you are very fast clicking the mouse, GLBasic might be faster so you can get mouse-down for two or more frames. This you need to keep track of yourself in your code.


This is the code I am using:
Code: (glbasic) [Select]
FUNCTION KeyHitUpdate:
GLOBAL b1State, b2State // Will contain 0=not pressed, 2=just pressed, -1=released, 1=mouse is down
STATIC b1Down, b2Down

MOUSESTATE mx, my, b1, b2
IF b1
IF b1Down
b1State=1
ELSE
b1Down = 1
b1State = 2
ENDIF
ELSE
IF b1Down
b1Down = 0
b1State = -1
ELSE
b1State = 0
ENDIF
ENDIF
IF b2
IF b2Down
b2State=1
ELSE
b2Down = 1
b2State = 2
ENDIF
ELSE
IF b2Down
b2Down = 0
b2State = -1
ELSE
b2State = 0
ENDIF
ENDIF
ENDFUNCTION

Usage:

Code: (glbasic) [Select]
//Game loop
WHILE TRUE
KeyHitUpdate() // Always first in the loop

PRINT "Mouse-State:" + b1State, 100,100
IF b1State=2
INC tips, 1
PRINT "Click!", 100, 120
ENDIF
IF b1State=-1
PRINT "Release", 100, 120
ENDIF

PRINT "Tipps"+tips, 100, 140

HIBERNATE  // Just for the example so it doesn't run so fast
SHOWSCREEN
WEND

Title: Re: MOUSESTATE sometimes causes trouble!
Post by: Kitty Hello on 2010-Feb-01
can't be. Mousestate must return button1 as what you actually pressed. Maybe you have variables swapped/mixed?
I mean, it could be, but I've nevers seen this in many years now and the internals are to call the directX driver directly on windows.
Don't set the active mouse, though.