• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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

B

bigtunacan

Guest
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?
 
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:

Morendral

Member
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
 
B

bigtunacan

Guest
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
 
Top