Instance destroy with mouse button release

Discussion in 'Programming' started by Lipman, Jun 14, 2017.

  1. Lipman

    Lipman Guest

    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)) {

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

    Any clues what I'm doing wrong?
  2. Yal

    Yal GMC Memer GMC Elder

    Jun 20, 2016
    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?
  3. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Apr 13, 2016
    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.
  4. Lipman

    Lipman Guest

    I tried it as you said:

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

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

    Lipman Guest

    Yeah, this one works, the easiest solution that I somehow missed, thanks!
  6. Perseus

    Perseus Not Ragarnak Forum Staff Moderator

    Dec 29, 2016
    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?

    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.
    Nocturne likes this.

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