Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
Tutorial explaining how to create doors in Adventurejs. tutorial, how to create a door

Get Started:Create a Door

Creating a door is just the same as creating any other asset, although right away you're going to see some new properties pertaining to doors.

MyGame.createAsset({
  class: "Door",
  name: "wood planked door",
  direction: "north",
  linked_asset: "iron bound door",
  place: { in:  "Dungeon Antechamber" },
  is: { 
    closed: true, 
    locked: true, 
  },
  description: "The imposing door is made of thick wooden planks, bound solidly together with corroded, but still quite strong, iron straps. ",
});

Take special note of the door's linked_asset property. That is how we link the door to its other side, which is another door in another room.

Adding in this door is going to change how we're doing some things. First let's go back to the "Dungeon Antechamber" constructor. In order to accommodate the new door, we're going to need to create an exit using createAsset so we can set some properties on it, which in turn means we're going to need to remove the north exit shortcut from "Dungeon Antechamber". We also need to revise the room description again.

MyGame.createAsset({
  class: "Room",
  name: "Dungeon Antechamber",
  description: "You're in a dingy dungeon antechamber. Every surface seems to be made of pitted cobblestones. A dark path descending to the north is bound by a massive wood planked door. The air here is dank and oppressive, leavened only by a slight draft of fresh air at your back. ",
  exits: 
  {
    // north: "Central Chamber",
    south: "You feel the lure of the tiny patch of sky that's still visible through the entrance... but you don't want to leave without the treasure! ",
  },
});

We've commented rather than removed the old north exit shortcut so you can see what was removed. Also, because doors aren't listed in rooms, we revised the room description to add an explicit reference to the door, ensuring that players see it. And, since the room's description refers to the wood planked door as massive, we added massive as an adjective to the wood planked door, so that players using the word are understood to be referring to the door.

#TMI About duplicate exits

If you were following along and happened to leave the original Dungeon Antechamber north exit shortcut in place after adding the new createAsset call, you might have seen an error like this.

If Adventurejs finds duplicate exits, it will halt the game initialization and print a warning like this to the browser's developer console.

Now, we're going to create a new exit to replace the old shortcut.

MyGame.createAsset({
  class: "Exit",
  direction: "north",
  place: { in:  "Dungeon Antechamber" },
  destination: "Central Chamber",
  // description: "You see a wall of cobbled stone inset with a heavy door. ",
  aperture: "wood planked door",
});

Take special note of the aperture property. That is how we assign a door to an exit.

To recap, we've created a door, and revised our room and exit to accommodate it. Now we'll do the same thing for the "Central Chamber" room.

// central chamber
MyGame.createAsset({
  class: "Room",
  name: "Central Chamber",
  description: "You're in the central chamber of the dungeon, a round room with a high stone ceiling. Paths in several directions are blocked by fallen stones. The path to the south is a touch brighter and emits a hint of sweeter air. ",
  exits:
  {
    // south: "Dungeon Antechamber",
  }
});
MyGame.createAsset({
  class: "Exit",
  direction: "south",
  place: { in:  "Central Chamber" },
  destination: "Dungeon Antechamber",
  // description: "A glimmer of daylight reaches you from the long antechamber corridor. ",
  aperture: "iron bound door",
});
MyGame.createAsset({
  class: "Door",
  name: "iron bound door",
  adjectives: ["massive"],
  direction: "south",
  linked_asset: "wood planked door",
  place: { in:  "Central Chamber" },
  is: { 
    closed: true, 
    locked: true, 
  },
  description: "The face of the door on this side is more iron than wood. You never would have been able to break it down. ",
});

Now we'll put it all together.

// game constructor block...
// player constructor block...

// dungeon antechamber
MyGame01.createAsset({
  class: "Room",
  name: "Dungeon Antechamber",
  description: "You're in a dingy dungeon antechamber. Every surface seems to be made of pitted cobblestones. A dark path descending to the north is bound by a massive wood planked door. The air here is dank and oppressive, leavened only by a slight draft of fresh air at your back. ",
  exits: 
  {
    north: "Central Chamber",
    south: "You feel the lure of the tiny patch of sky that's still visible through the entrance... but you don't want to leave without the treasure! ",
  },
});
MyGame01.createAsset({
  class: "Exit",
  direction: "north",
  place: { in:  "Dungeon Antechamber" },
  destination: "Central Chamber",
  // description: "You see a wall of cobbled stone inset with a heavy door. ",
  aperture: "wood planked door",
});
MyGame01.createAsset({
  class: "Door",
  name: "wood planked door",
  adjectives: ["massive"],
  place: { in:  "Dungeon Antechamber" },
  is: { 
    closed: true, 
    locked: true, 
  },
  linked_asset: "iron bound door",
  direction: "north",
  description: "The imposing door is made of thick wooden planks, bound solidly together with corroded, but still quite strong, iron straps. ",
});

// central chamber
MyGame01.createAsset({
  class: "Room",
  name: "Central Chamber",
  description: "You're in the central chamber of the dungeon, a round room with a high stone ceiling. Paths in several directions are blocked by fallen stones. The path to the south is a touch brighter and emits a hint of sweeter air. ",
  exits:
  {
    // south: "Dungeon Antechamber",
  }
});
MyGame01.createAsset({
  class: "Exit",
  direction: "south",
  place: { in:  "Central Chamber" },
  destination: "Dungeon Antechamber",
  // description: "A glimmer of daylight reaches you from the long antechamber corridor. ",
  aperture: "iron bound door",
});
MyGame01.createAsset({
  class: "Door",
  name: "iron bound door",
  adjectives: ["massive"],
  direction: "south",
  linked_asset: "wood planked door",
  place: { in:  "Central Chamber" },
  is: { 
    closed: true, 
    locked: true, 
  },
  description: "The face of the door on this side is more iron than wood. You never would have been able to break it down. ",
});

At last we have two rooms with connecting doors between them. Unfortunately the doors are locked and we have no key!

NEXT: Create a Key