• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker id only returning on first instance

C

Clusta626

Guest
Hi all, thanks for your help in advance, I've looked across the forums and read the documentation on id and instances and cant seem to work out what is going wrong. It's possible I just don't understand the nature of instance Id's. Any help is greatly appreciated.

I'm using a position_meeting to cause instances to change on a mouse over and trying to get the instance with the mouse over it to grow slightly and register its id to a variable. There are multiple instances of the same object with the below code as a step event. All instances change scale when the mouse hits them(as desired) but the two global variables only change when the mouse is over the first instance of the object in the room. If the mouse is over any of the other instances the two global variables both stay at 0. I tried replacing the "id" fixed variable with "self" and "image_id" but this didn't work.

Code:
if position_meeting(mouse_x,mouse_y,id)
{
    image_xscale = 1.1;
    image_yscale = 1.1;
    global.anchor_selected = id;
    global.anchor_able = true;
} else
{

    image_xscale = 1;
    image_yscale = 1;
    global.anchor_selected = 0;
    global.anchor_able = false;
}
Thanks again in advance.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Whatever instance sets your globals, the others set them right back to 0. Unless, of course, the one you're hovering above is the last one to execute that code.
 
C

Catastrophe

Guest
You probably want to handle this outside of your object. E.g. in some controller

global.anchor_selected = 0;
global.anchor_able = false;
with (yourObjectTypeName){
if position_meeting(mouse_x,mouse_y,id)
{
image_xscale = 1.1;
image_yscale = 1.1;
global.anchor_selected = id;
global.anchor_able = true;
} else {
image_xscale = 1;
image_yscale = 1;
}
}

That's a way to get your globals working correctly exactly, although there may be an easier way of doing this if we knew where these anchor variables were used.
 
C

Clusta626

Guest
Ah, Yes of course that makes sense. I've managed a workaround where instead of saying "if any anchors aren't selected then variable is false" and made it "if no anchors are selected then variables equal false" That's got it working.
Code:
if position_meeting(mouse_x,mouse_y,id)
{
    image_xscale = 1.1;
    image_yscale = 1.1;
    global.anchor_selected = id;
    global.anchor_able = true;
}
else if !position_meeting(mouse_x,mouse_y,ob_anchor)
{
    image_xscale = 1;
    image_yscale = 1;
    global.anchor_selected = -0;
    global.anchor_able = false;
}
It was a simple solution in the end, I just didn't have eyes to see it.

Thanks for all the help.
 
Top