How to block/cancel mouse event?

Discussion in 'Programming' started by bsabiston, Aug 26, 2019.

  1. bsabiston

    bsabiston Member

    Joined:
    Jun 21, 2016
    Posts:
    206
    I have a big menu overlay that pops up from time to time, covering my regular object-based buttons. The menu is not an object -- I detect UI touches using mouse_check_button().

    Is there a way that when I detect mouse down and handle the mouse click in my menu overlay, I can then cancel the mouse from going on and triggering the buttons underneath?

    I know that with button click handling you can return true to say the event was handled. But in the case of mouse_check_button, there's no event (yet?). So can I get the event that is or would be generated and cancel that?

    Thanks!
     
  2. Zhanghua

    Zhanghua Member

    Joined:
    Aug 3, 2017
    Posts:
    167
    Just the FSM....
     
  3. MONCEFDZ

    MONCEFDZ Member

    Joined:
    Jul 18, 2019
    Posts:
    3
    with
    Code:
    exit;
    the lines before this keyword will not stop
    but the lines after the keyword will stop
    i hope this what you mean
     
    ParodyKnaveBob likes this.
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,688
    Wrap all the code triggered by the normal buttons in something like
    Code:
    if not(instance_exists(obj_bigmenuthing){
       //Original code here
    }
    
    then it's not run if the menu exists.
     
  5. bsabiston

    bsabiston Member

    Joined:
    Jun 21, 2016
    Posts:
    206
    What is that - sorry I don’t understand
     
  6. Zhanghua

    Zhanghua Member

    Joined:
    Aug 3, 2017
    Posts:
    167
    Use finite state machine to manage your game logic
     
  7. bsabiston

    bsabiston Member

    Joined:
    Jun 21, 2016
    Posts:
    206
    ???
    Sigh
     
  8. Zhanghua

    Zhanghua Member

    Joined:
    Aug 3, 2017
    Posts:
    167
    I think that this project you write now is hard to maintain without code structure management.... cause I had done this before.
     
  9. bsabiston

    bsabiston Member

    Joined:
    Jun 21, 2016
    Posts:
    206
    I appreciate why you would say that, but this is a special case that does not warrant rewriting the basic structure of a codebase that’s already been used to publish two fairly successful games. Thanks to everyone who replied, I assumed there would be a way to do what I asked. But I have figured out a workaround which won’t require major code reworking.
     
    Zhanghua likes this.
  10. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    412
    Yal got your answer you set a variable true false when the overlay is visable then put an if block around your mouse click on the objects. They will still detect the click but the if statement will cancel the undesired action.
     
  11. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,885
    Let's address the elephant in the room.

    Suppose the menu is a moveable overlay, similar to most MMORPGs. A "if window is open" check won't work because the overlay could be over the other button or it could be on the other side of the screen, so neither would a state machine centered around a similar mechanic. You'd need to organize the game such that the overlay is guaranteed to run its code first and then mouse_clear(mb_any) afterward.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice