[SOLVED] Stop global click events from firing? (GML)

Discussion in 'Programming' started by bigtunacan, Jan 8, 2019.

  1. bigtunacan

    bigtunacan Member

    Joined:
    Aug 5, 2016
    Posts:
    60
    I'm using global events to handle things like having the character jump, but then I also have menu buttons that will need to be clicked to different in game actions. Currently what is happening is that the button gets clicked and the button works fine as it uses a local click event, but then the global event is causing an unwanted jump to occur.

    Is there an easy way to prevent this behavior?
     
  2. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    985
    Perhaps put a mouse position check in the global click event? There's multiple ways to fix this behaviour, but we'd need to understand more about what's going on. If you did something like this inside of the global mouse event, it'll only fire if it's not in the button's positions:
    Code:
    if (!point_in_rectangle(mouse_x,mouse_y,button_left_pos,button_top_pos,button_right_pos,button_bottom_pos)) { // button_left_pos, etc are just placeholders I'm using for your button's position
       // Execute jumping code
    }
    If you have a whole area devoted to the menu buttons, replace the button_left_pos, etc with the entire menu area for the global mouse event to ignore all clicks in the menu.
     
    Last edited: Jan 8, 2019
    CheeseMyBaby likes this.
  3. Morendral

    Morendral Member

    Joined:
    Jun 27, 2016
    Posts:
    348
    There are many ways to handle this, actually. In addition to above you could make a game paused variable which your game objects check for. If you need them to be clicked not while it's paused, the method posted above works but checking that each step has a lot of cpu over head. You could try breaking that apart into a bunch of nested "if"s checking each side of the box.

    That's assuming that you are doing it in the gui layer, and don't have the menu button as a separate object. If you do, just have that object trigger a global variable when the mouse is over it, and then have your player character check that variable before executing that code
     
    RefresherTowel likes this.
  4. bigtunacan

    bigtunacan Member

    Joined:
    Aug 5, 2016
    Posts:
    60
    Thank you both. I tried the method @Morendral mentioned as it does seem simpler, but I couldn't quite get that working. I was able to get it working using the bounding box check like you suggested @RefresherTowel
     

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