L
lonecandle
Guest
Hi all, I´m just starting out with GM:S and I´m almost sure I misunderstood the real meaning of these two lines of code.
I´ll just shortly describe what I´m trying to achieve:
Let´s say I have a group of instances - buttons - with one parent - the parent button - distributed in the room. (For clarity; the parent button is also present in the room, together with the others, which are just smaller buttons with "the parent button" assigned as a parent).
I then have a "global tap" event in the parent button, and I want to check its distance of the point of the tap (posX, posY). Since there are more "buttons" in the room, all of which I want this to be applied to, I thought it would be ellegant to do this only in the parent button, to have the possibility of placement of however many "buttons" I choose and this check being applied to all of them.
The result I aim for is that whenever I tap on the screen, the button which is closest to the tap will be pressed.
How do I check for this? I came up with this most probably nonsensical code:
My logic was: If instance_id (=if this particular instance (?) ) is the nearest instance to the tap, then "press me" (=this particular button). Here´s where I need advice - have I misunderstood the function of the instance_id variable? How can I point to the instance itself through its own action and then check whether it's the nearest one to the position of the tap?
I sincerely hope I was clear enough with this and I hope there still are friendly souls lurking around forums like this who will find the time to answer this question. Thank you very much in advance, looking forward to seeing any replies!!
LC
I´ll just shortly describe what I´m trying to achieve:
Let´s say I have a group of instances - buttons - with one parent - the parent button - distributed in the room. (For clarity; the parent button is also present in the room, together with the others, which are just smaller buttons with "the parent button" assigned as a parent).
I then have a "global tap" event in the parent button, and I want to check its distance of the point of the tap (posX, posY). Since there are more "buttons" in the room, all of which I want this to be applied to, I thought it would be ellegant to do this only in the parent button, to have the possibility of placement of however many "buttons" I choose and this check being applied to all of them.
The result I aim for is that whenever I tap on the screen, the button which is closest to the tap will be pressed.
How do I check for this? I came up with this most probably nonsensical code:
GML:
if instance_id = instance_nearest(event_data[? "posX"], event_data[? "posY"] , self)
//PRESS ME (not coded yet)//
I sincerely hope I was clear enough with this and I hope there still are friendly souls lurking around forums like this who will find the time to answer this question. Thank you very much in advance, looking forward to seeing any replies!!
LC