Author Topic: MOUSESTATE sometimes causes trouble!  (Read 2113 times)

Offline Ozden79

  • Mr. Polyvector
  • ***
  • Posts: 121
    • View Profile
MOUSESTATE sometimes causes trouble!
« 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

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1754
    • View Profile
    • Homepage
Re: MOUSESTATE sometimes causes trouble!
« Reply #1 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.

Offline Ozden79

  • Mr. Polyvector
  • ***
  • Posts: 121
    • View Profile
Re: MOUSESTATE sometimes causes trouble!
« Reply #2 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

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1607
  • Particle Hawk
    • View Profile
Re: MOUSESTATE sometimes causes trouble!
« Reply #3 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.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Ozden79

  • Mr. Polyvector
  • ***
  • Posts: 121
    • View Profile
Re: MOUSESTATE sometimes causes trouble!
« Reply #4 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

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1607
  • Particle Hawk
    • View Profile
Re: MOUSESTATE sometimes causes trouble!
« Reply #5 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.

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1754
    • View Profile
    • Homepage
Re: MOUSESTATE sometimes causes trouble!
« Reply #6 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

 

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10675
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: MOUSESTATE sometimes causes trouble!
« Reply #7 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.