GM:S 1.4 Finding the nearest object out of several

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

  1. popjin

    popjin Member

    Joined:
    Jun 22, 2016
    Posts:
    17
    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

    Joined:
    Jun 20, 2016
    Posts:
    565
    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

    Joined:
    Jun 24, 2016
    Posts:
    1,859
    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):
    Code:
    DOOR CREATION CODE:
    DoorName = "PodBayDoors";
    
    CONTROL PANEL CREATION CODE (the panel that is meant to link to the door)
    LinkedDoorId = noone;
    LinkedDoorName = "PodBayDoors";
    with(obj_door){
        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

    Joined:
    Jun 20, 2016
    Posts:
    3,460
    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