• 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 [SOLVED] Problem with ids

Zabicka

Member
I have one object that is called "obj_door", I made a variable in "variable definitions" called "room_next" in the door object and it's a boolean, I have two of the door objects in the same room and I want the player to spawn on top of the door that is "false", and the second door with "true" to just teleport you to another room.

So I need to get the x and y positions of the door with "false" when the room starts, but I don't know how to get these positions.

I tried this in the room start event in the player object, but it doesn't work.

Code:
if (instance_exists(obj_door)) {
    if (obj_door.object_index == false) {
        x = obj_door.x;
        y = obj_door.y;
    }
}
 

CloseRange

Member
firstly obj_door will only return the instance of ONE of the door objects, it can't ever refer to more than one object. So this object could be either one of the doors. What you want is "with(obj_door) { }"
Secondly object_index refers to the object type.
So if I said with(object_index) in the player object, this would run on every obj_player object.
Thirdly room_next is a built in function so you can't make it into a variable.
So choose a new name for a variable, I'll just say you made it "is_next"
and do this instead:
Code:
if (instance_exists(obj_door)) {
    with(obj_door) {
        if(!is_next) {
            other.x = x;
            other.y = y;
        }
    }
}
 
R

relic1882

Guest
object_index returns the number of the instance of the door, not a boolean. You want to search all instances of your door, then use the one that is "false" to get the x and y coordinates. I'm not sure what you're going with exactly but from what I'm understanding you can try something like this. The only thing is that you'd have your true/false Boolean within your door object.

Code:
for(var i = 0; i <instance_number(obj_yourDoor); i++)    //cycle through instances of doors
{
    var inst = instance_find(i);                          //assign current instance of door to a temp instance variable
    if inst.trueOrFalseDoorVariable = false       //check boolean of current door
    {
                //assign coordinates based on current "false" door
                 x = inst.x;
                 y = inst.y;
                 break;            //stop the loop
    }
}
Good luck with your project!

Edit: CloseRange beat me to it. Their way is simpler and essentially does the same thing as I did if I'm correct.
 

Zabicka

Member
firstly obj_door will only return the instance of ONE of the door objects, it can't ever refer to more than one object. So this object could be either one of the doors. What you want is "with(obj_door) { }"
Secondly object_index refers to the object type.
So if I said with(object_index) in the player object, this would run on every obj_player object.
Thirdly room_next is a built in function so you can't make it into a variable.
So choose a new name for a variable, I'll just say you made it "is_next"
and do this instead:
Code:
if (instance_exists(obj_door)) {
    with(obj_door) {
        if(!is_next) {
            other.x = x;
            other.y = y;
        }
    }
}
Thank you so much! That works very well! (I actually did a mistake here, my variable is called door_next not room_next, my fault, sorry.)
 
Top