GMS 2 If Instance Clicked

S

Sahibjot Cheema

Guest
I have created a bunch of instances, I want to know how I would know if I clicked it because position_meeting() would activate all of them. It's a pretty simple problem but I haven't been able to find any answer anywhere.
 

Alix

Member
Store the ID of the instance that you click on with a mouse click event ? Every instance has a unique 'id' variable.
 
S

Sahibjot Cheema

Guest
Store the ID of the instance that you click on with a mouse click event ? Every instance has a unique 'id' variable.
Could you put that in more detail.
 
Last edited by a moderator:

2Dcube

Member
The function position_meeting() returns the id of the instance you clicked.
Code:
instance_id = position_meeting( .... );
So if you want to only affect that one instance:
Code:
instance_id = position_meeting( .... );
if (instance_id != noone) // make sure we actually clicked an instance
{
  with( instance_id )
  {
      activate();
  }
}
 

Paskaler

Member
Just to amend what @2Dcube posted: position_meeting returns either true or false, to get the instance's id back, use instance_position instead:

Code:
  with( instance_position( mouse_x, mouse_y, <my_instance_or_my_object> ) )
  {
     activate();
  }
The with statement won't run if the instance is not found, too, so the outer check is unnecesary.
 
Top