1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Finding the nearest object out of several

Discussion in 'Programming' started by popjin, Jun 27, 2016.

  1. popjin

    popjin Member

    Jun 22, 2016
    Hi everyone,
    I have recently been working on a game and I am having a bit of difficulty.
    My game is a sci-fi game where the doors are controlled by control panels which are placed next to each other in the room editor.
    When created, they detect the nearest door and save it. However, this only works for one type of door.
    But when you have multiple doors, you would need several instance_nearest commands and you would need to somehow compare them to assign the right door, and so my question is how you would do this.

    Thanks in advance and feel free to ask for code, images, ect.
    Last edited: Jul 3, 2016
  2. hippyman

    hippyman Member

    Jun 20, 2016
    If you have more than one kind of door then you should make a parent Door object and make all the door objects children of the parent.
    Then check instance nearest with the parent object and it will check for all of the children as well. Only one instance position needed.
    Zerb Games likes this.
  3. NightFrost

    NightFrost Member

    Jun 24, 2016
    In case you didn't already know; you can, if you want to, uniquely identify each door and use that to link it to a specific control panel. To uniquely identify a door, go into the room editor, right click a door and select Creation Code. Here you can enter a code block that will be given only to the specific instance of the door you selected. So you could do something like (assuming your door object is called obj_door):
    DoorName = "PodBayDoors";
    CONTROL PANEL CREATION CODE (the panel that is meant to link to the door)
    LinkedDoorId = noone;
    LinkedDoorName = "PodBayDoors";
        if(DoorName == other.LinkedDoorName) other.LinkedDoorId = id;
    Do this for each door and control panel pair, changing DoorName and LinkedDoorName each time. Afterwards, in control panel's step event you can point to the linked door's id through the LinkedDoorId variable.

    Edit - make sure in room's Instance Order, doors are before the control panels.
  4. Yal

    Yal GMC Memer GMC Elder

    Jun 20, 2016
    Is the problem about multiple door types or panels that opens several doors at once? Like the 3-4 nearest doors?

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