• 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!

GML why is mouse global?

S

Swegm

Guest
Hi

I have too big leaps from game maker, so i forget what im doing haha
but anyway i have a button wich is called

obj_button_house
Create Event:

image_speed = 0
image_index = 0

Step Event:

if (mouse_check_button_pressed(mb_left))
{
image_index = 1
cursor_sprite = spr_house
}
else
if mouse_check_button_released(mb_left)
{
image_index = 0
}


well it seems like even if i press outside far away from the button, it reacts and run the code..hmmm like its global
 

TheouAegis

Member
Because fundamentally it is much easier to treat the mouse globally rather than relative to the instance the code is in.
 

2Dcube

Member
If you want to check if you're pressing on an object you could do something like this:

Code:
if (mouse_check_button_pressed(mb_left) && point_in_rectangle(mouse_x, mouse_y, x-32, y-32, x+32, y+32))
{
  //...
}
 
S

Swegm

Guest
If you want to check if you're pressing on an object you could do something like this:

Code:
if (mouse_check_button_pressed(mb_left) && point_in_rectangle(mouse_x, mouse_y, x-32, y-32, x+32, y+32))
{
  //...
}
this sounds like an answer, will try that thanks !
 

TsukaYuriko

☄️
Forum Staff
Moderator
You may be confusing this function with the Mouse events. Those are local. (Global mouse events are global, of course.)

The naming of these functions actually tells you exactly what they do, though: check if a mouse button was pressed. Nowhere does it say that it checks whether something was clicked on. It's the events that suffer from unfortunate naming.

If you wish to emulate the Mouse events, a call to position_meeting using the mouse's coordinates as the position and the calling instance's ID as the instance to check should be sufficient.
 
S

Swegm

Guest
You may be confusing this function with the Mouse events. Those are local. (Global mouse events are global, of course.)

The naming of these functions actually tells you exactly what they do, though: check if a mouse button was pressed. Nowhere does it say that it checks whether something was clicked on. It's the events that suffer from unfortunate naming.

If you wish to emulate the Mouse events, a call to position_meeting using the mouse's coordinates as the position and the calling instance's ID as the instance to check should be sufficient.
Thanks this is helpful for me!
I did't think about it that way. i thought game maker knew what i meant haha :p we'll probably wait few more years until game maker have an AI
interpreters our code and can figure out what we want to do.
Anyway i think i got it working now with your help. have a nice weekend ! thanks again!
 
Top