Place_meeting / Position_meeting not working

SpiceEdge

Member
I have written this simple code that just checks if you're hovering over the object and if you press mb_left it does something.
But it doesn't seem to even acknowledge that I'm hovering over the object. I have tried using "place_meeting(mouse_x, mouse_y, self)" and "position_meeting(mouse_x, mouse_y, id)" or "position_meeting(mouse_x, mouse_y, self)" but it doesn't seem to work. And yes the object does have a colision mask and yes I can clearly see that it has been created and is visible on the screen.
Does anyone know what the problem is?

GML:
if (place_meeting(mouse_x, mouse_y, self)) {
    show_message("hovering"); //debug
    if (mouse_check_button_released(mb_left)) {
        //something that I removed from here cuz not necessary
    }
}
This code is in the step event and has worked correctly in other objects, so I don't know why it doesn't work on this one specifically.
 

Nidoking

Member
I don't think place_meeting ever works with self. Instances aren't considered to collide with themselves - that would cause a colossal mess with collisions. position_meeting with id should work - are you doing something with views that might mean the mouse coordinates don't match the instance's mask?
 
If you need a "Hovering" variable, I personally use Mouse Enter/Leave events. With those, it's as simple as toggling a bool.
You could also do this if you absolutely want to use self, but looks much uglier to me and has no added benefit whatsoever in this case:
GML:
var _id = self.id;          //Notice the subtilty, here

if (instance_position(mouse_x, mouse_y, _id) != noone) {
    show_debug_message("hovering");
}
I don't think place_meeting ever works with self.
Not like he did, as you gotta pass an object or instance id, and self won't return that. self.id will, tho.
 

kupo15

Member
if you wanted to use code, it would be better to use point_in_rectangle then pass in mouse x and y and bbox for the rectangle. Mouse isn't an object so it wouldn't trigger a collision
 

Nidoking

Member
That would be less helpful because it doesn't return an instance ID
What ID is it going to return? You've only passed in an instance ID, so either it meets that instance or it doesn't. That's a true or false, which is all you need. Comparing a boolean to noone doesn't make sense, but surely, people are reading the Manual for the functions they use, recognizing that they're getting a boolean, and writing their checks appropriately.
 

samspade

Member
Maybe I'm confused, but does the OP need an instance id? It looks like they just want a true/false value to trigger the if statement and the code is inside of the instance itself (I use code virtually identical to this all the time only with the function that I posted for that purpose).

Another important note is that the object using this code has to have a mask assigned to it (and of course that mask has to be where you think it is). The OP says it does though in the post. It might be worth both double checking the mask and perhaps drawing the bounding box or inspecting the bounding box variables in the debugger to make sure the mouse values are inside the bounding box. I assume it's not being drawn in the room and not on the gui layer?
 
Last edited:

BB Scary

Member
Tray use event mouse enter. Here put your code
GML:
show_message("hovering"); //debug
if (mouse_check_button_released(mb_left)) {
    //something that I removed from here cuz not necessary
}
 

Nidoking

Member
You really don't want to put that in Mouse Enter. It will only trigger if you release the mouse button in exactly the same step when it enters the instance. You might try removing the check entirely and just using the Mouse Released event.
 

Sporkinator

Member
You really don't want to put that in Mouse Enter. It will only trigger if you release the mouse button in exactly the same step when it enters the instance. You might try removing the check entirely and just using the Mouse Released event.
I suspect the intention might be to check if the mouse button is NOT being held, in the mouse enter event, in which case it would be if (!mouse_check_button(mb_left))
 

kupo15

Member
What ID is it going to return? You've only passed in an instance ID, so either it meets that instance or it doesn't. That's a true or false, which is all you need. Comparing a boolean to noone doesn't make sense, but surely, people are reading the Manual for the functions they use, recognizing that they're getting a boolean, and writing their checks appropriately.
well I guess it depends on what is calling the check. If its a controller object then you would want the id of the instance you are clicking on to do things to it. I guess there isn't a point if each instance is calling the collision check with the mouse though
 

Nidoking

Member
well I guess it depends on what is calling the check.
The call you quoted, the actual specific code about which you said what you said, was passing id to position_meeting. What is calling the check is, by definition, the instance being checked. There is no other possible context for the specific call you quoted. And to be more general, passing ANY single instance ID into position_meeting will only ever check one instance. It is the instance whose ID you passed in. You already know the ID of this instance. Because you passed it into the function. It is the instance ID you passed in. That is the ID. There is no new information you can possibly obtain from an instance ID when you already know what it is.
 

SpiceEdge

Member
Lmao the fighting in this post. I'll try to clarify my intention even though it is already written in the post.

I am trying, in the step event of the object itself, to check if the mouse is above the object's collision mask. (I have made sure that the collision mask is set up correctly multiple times, so I doubt it's the collision mask) And if the mouse is in the collision mask of the object, in other words, if the mouse is hovering over the object, I want it to trigger something. But I have used "show_message" in order to debug to see if the code even recognizes that I'm hovering over the object, and it doesn't.

I had mentioned in the post aswell, that I used the exact same principle with "place_meeting(mouse_x, mouse_y, self)" in other objects and it worked fine. Which does lead me to think it might be the collision mask, though I also set up the collision mask exactly like any other object.
What I did: I just made a sprite, made an object, gave the object the sprite, made sure that the sprite does have a collision box (I could clearly see the box), made a create and step event, and put that code into the step event. It's that simple.

I have - like you guys said, and I myself also said in the post - tried using "position_meeting" with "id" and with "self" both of which did not work either.

I truly don't understand what you guys were confused about tho. Everything you guys said you weren't sure on was literally written in the post?! It's fine though, hopefully I clarified it now.
 

SpiceEdge

Member
SOLVED - I have changed it once again to "position_meeting(..., id)" and now it works. I guess it was a gamemaker studio bug while I was using it.
 
Top