Instance destroy with mouse button release

L

Lipman

Guest
Hi,
I've been trying to write a piece of code that would destroy an instance with mouse button release. I tried the below, but it wouldn't work - none visible action is performed:

if (mouse_check_button_released(mb_left) && position_meeting(mouse_x, mouse_y, id)) {
instance_destroy();
}

However, the above works when the mouse_checked_button_pressed is used instead.

Any clues what I'm doing wrong?
 

Yal

šŸ§ *penguin noises*
GMC Elder
There are specific Events for when you click or release the mouse button while hovering an instance, wouldn't it be easier to use those?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Position_meeting requires an instance with a collision mask to work. you need ti use instance_position instead which takes a point in room space to check for a collision.
 
L

Lipman

Guest
Position_meeting requires an instance with a collision mask to work. you need ti use instance_position instead which takes a point in room space to check for a collision.
I tried it as you said:

if (mouse_check_button_released(mb_left) && instance_position(mouse_x, mouse_y, my_object) ) {
instance_destroy()
}

And the result is the same none visible action performed, but when changed to mouse_check_button_pressed it works
 
L

Lipman

Guest
There are specific Events for when you click or release the mouse button while hovering an instance, wouldn't it be easier to use those?
Yeah, this one works, the easiest solution that I somehow missed, thanks!
 

Perseus

Not Medusa
Forum Staff
Moderator
And the result is the same none visible action performed,
Odd. That code (and the one in your first post) should have been working fine as long as the instance calling it had a valid collision mask. Except you should have been checking if instance_position doesn't return noone. It would have worked either way, though, due to how GM treats values larger than 0.5 as true and others as false.

Although you've solved the problem, I'm interested in knowing what could possibly be going wrong down there. So I hope you don't mind me asking you a few questions: What version are you on? What event is this put in? Are you sure that another instance doesn't get created upon mouse button release for whatever reason? Have you tried putting a couple of show_debug_message calls in there? Is there any other code? Are you sure that you've not touched those "Applies To" radio buttons by any chance? Is it something isolated to a single project of yours? Did you try doing the same in an empty new project? What exactly did work for you at last?

Position_meeting requires an instance with a collision mask to work. you need ti use instance_position instead which takes a point in room space to check for a collision.
Looks like you mixed up place_meeting and position_meeting there. The latter by itself uses a point in room space to detect collisions, unlike the former.
 
Top