Opening and closing
You can open or close a door from your mod. Both calls give back a bool that tells you whether it worked, and neither throws an error.
Doors opens and closes doors
Call Open or Close with a door’s id, and check the bool it returns.
public static class Doors
{
public static bool Open(string id);
public static bool Close(string id);
}
| Method | Returns | What it does |
|---|---|---|
Open(id) | bool | Opens the door. true when it is now open or opening. |
Close(id) | bool | Closes the door. true when it is closed or closing. |
Things to know
Opengivestruewhen the door is open after the call. (The result isDoor.doorIsOpenafter the call. A door withnoOppositeDirectionandinvertOppositeDirectionset opens through the game’sOpenOpposite.IsOpenand the events still followdoorIsOpen.)Closedoes not check locks, just like the game’s own close. It givestruewhen the door is already closed or is now closing. (It calls the publicDoor.Close(), which does nothing at position 0. The result is true whendoorIsOpenis false orDoorIsOpenOrAjar()is true.)- Do not call
IsOpenon every frame to wait for a change. Each call searches every door in the scene. Listen forOpenedandClosedinstead.
Limits
Opendoes not open a locked door, and it givesfalsefor one. To open a locked door, unlock it first. TheLockscalls are on the Interaction page. Otherwise the game would use the player’s key, start the player’s lockpick game, or play the “locked” sound. (It returnsfalsewithout touching the door whenDoor.Lockedis true. Otherwise it calls the game’s publicDoor.Open(). Without the check,Lock.Usewould use the key or start the lockpick, and a door that is already closing would open again even when locked. A door that opens through a key goes through the game’s unlock, soLocks.Unlockedfires as well.)- Both give
falsewhile a save is loading or being written, and for an id the game does not know. (Both checkSaveData.Busyfirst.) Closegivesfalsein the very first moment of an opening, when the door has not started to move yet and the game ignores the close.