Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
Tutorial explaining how to set asset descriptions in AdventureJS. tutorial, descriptions

Advanced Descriptions:Exit Lists

Exit lists have a special set of description settings. What's an exit list? When a player enters a room, typically the game shows them a description of the room, which often includes a list of exits from the room. There are a number of settings to control whether and how the room's exits are listed, and then there are additional methods to customize each exit in a list. To start with, we'll create a basic room asset with shorthand exit definitions.

MyGame.createAsset({
  class: "Room",
  name: "Piano Room",
  description: `The tiny room is dominated by a grand piano. `,
  exits: {
    east: "Cello Room",
    west: "Viola Room",
    north: "Tuba Room",
    south: "Holophoner Room",
  },
});

The default setting is to list exits, but for the sake of this example, we'll say that no options are set. In that case, a player would see the room description with no exits listed.

Piano Room
The tiny room is dominated by a grand piano.
  • room.print_exits game.settings.print_exits

    If either of these is true, a list of the room's exits will be appended to the room's description.

    Expand for example

    We can enable printing exits globally. (As mentioned, the default setting is true, but for the sake of the example we're assuming it's false).

    MyGame.settings.set({
      print_exits: true,
    });
    

    If you choose to disable printing exits globally, you can still enable it for one room; or alternately, enable globally and disable for one room.

    MyGame.createAsset({
      class: "Room",
      name: "Piano Room",
      print_exits: true,
      description: `The tiny room is dominated by a grand piano. `,
      exits: {
        east: "Cello Room",
        west: "Viola Room",
        north: "Tuba Room",
        south: "Holophoner Room",
      },
    });
    

    The results would look like this in-game.

    Piano Room
    The tiny room is dominated by a grand piano.
    You can go east, west, north, or south.
  • room.print_room_names_in_exits game.settings.print_room_names_in_exits

    If either of these is true, a room's exits list will include the names of the rooms they lead to.

    Expand for example

    We can set whether to show room names globally.

    MyGame.settings.set({
      print_exits: true,
      print_room_names_in_exits: true,
    });
    

    Or we can set whether to show room names per room.

    MyGame.createAsset({
      class: "Room",
      name: "Piano Room",
      print_exits: true,
      print_room_names_in_exits: true,
      description: `The tiny room is dominated by a grand piano. `,
      exits: {
        east: "Cello Room",
        west: "Viola Room",
        north: "Tuba Room",
        south: "Holophoner Room",
      },
    });
    

    The results would look like this in-game.

    Piano Room
    The tiny room is dominated by a grand piano.
    You can go east to the Cello Room, west to the Viola Room, north to the Tuba Room, or south to the Holophoner Room.
  • room.print_room_names_in_exits_if_known game.settings.print_room_names_in_exits_if_known

    If either of these is true, when a room's exits are listed, only the names of rooms known by the player will be shown. In this case, you might see a mix of exits with and without room names, depending on what rooms the player knows about.

    • This is a modifier for print_room_names_in_exits and requires that it is also set to true.
    • There is an important distinction between print_room_names_in_exits_if_known and print_room_names_in_exits_if_used. The former asks whether the room is known; the latter asks whether the exit has been used; as it's entirely possible that a player might know about a room without having used an exit.
    Expand for example

    We can set this property globally.

    MyGame.settings.set({
      print_exits: true,
      print_room_names_in_exits: true,
      print_room_names_in_exits_if_known: true,
    });
    

    Or we can set this property per room.

    MyGame.createAsset({
      class: "Room",
      name: "Piano Room",
      print_exits: true,
      print_room_names_in_exits: true,
      print_room_names_in_exits_if_known: true,
      description: `The tiny room is dominated by a grand piano. `,
      exits: {
        east: "Cello Room",
        west: "Viola Room",
        north: "Tuba Room",
        south: "Holophoner Room",
      },
    });
    

    Assuming that the Holophoner Room is the only room known, the results would look like this in-game.

    Piano Room
    The tiny room is dominated by a grand piano.
    You can go east, west, north, or south to the Holophoner Room.
  • room.print_room_names_in_exits_if_used game.settings.print_room_names_in_exits_if_used

    If either of these is true, when a room's exits are listed, only exits that have been used by the player will have their names shown. In this case, you might see a mix of exits with and without room names, depending on what exits the player has used.

    • This is a modifier for print_room_names_in_exits and requires that it is also set to true.
    • There is an important distinction between print_room_names_in_exits_if_known and print_room_names_in_exits_if_used. The former asks whether the room is known; the latter asks whether the exit has been used; as it's entirely possible that a player might know about a room without having used an exit.
    Expand for example

    We can set this property globally.

    MyGame.settings.set({
      print_exits: true,
      print_room_names_in_exits: true,
      print_room_names_in_exits_if_known: true,
      print_room_names_in_exits_if_used: true,
    });
    

    Or we can set this property per room.

    MyGame.createAsset({
      class: "Room",
      name: "Piano Room",
      print_exits: true,
      print_room_names_in_exits: true,
      print_room_names_in_exits_if_known: true,
      print_room_names_in_exits_if_used: true,
      description: `The tiny room is dominated by a grand piano. `,
      exits: {
        east: "Cello Room",
        west: "Viola Room",
        north: "Tuba Room",
        south: "Holophoner Room",
      },
    });
    

    Assuming that only the east and west exits have been used, the results would look like this in-game.

    Piano Room
    The tiny room is dominated by a grand piano.
    You can go east to the Cello Room, west to the Viola Room, north, or south.
  • room.descriptions.exits

    If a room has its exits description set, that will be printed instead of the default list. This takes precedence over individual exit descriptions.

    Expand for example
    MyGame.createAsset({
      class: "Room",
      name: "Piano Room",
      descriptions: {
        look: `The tiny room is dominated by a grand piano. `,
        exits: `It appears that {we} may be able to squeeze around the grand piano to the north, south, east or west to reach the other instrument rooms. `,
      },
      exits: {
        east: "Cello Room",
        west: "Viola Room",
        north: "Tuba Room",
        south: "Holophoner Room",
      },
    });
    

    The results would look like this in-game.

    Piano Room
    The tiny room is dominated by a grand piano.
    It appears that you may be able to squeeze around the grand piano to the north, south, east or west to reach the other instrument rooms.
  • exit.descriptions.listing

    If an individual exit has a listing description set, that will be printed instead of the generic exit name. Individual exit descriptions may be overridden by the room's exits description. The previous examples all use the room.exits shortcut method of making exits. In order to set an exit's description property, we have to use the long form of creating an exit. Since we can mix & match short form and long form exit definitions, in this example, we'll separate out the Holophoner exit for special treatment. While we're working with it, we'll also give it a travel description, to be printed when a user travels through the exit.

    Expand for example
    MyGame.createAsset({
      class: "Room",
      name: "Piano Room",
      description: `The tiny room is dominated by a grand piano. `,
      exits: {
        east: "Cello Room",
        west: "Viola Room",
        north: "Tuba Room",
        // south: "Holophoner Room", // we're replacing this
      },
    });
    
    MyGame.createAsset({
      class: "Exit",
      direction: "south",
      place: { in: "Piano Room" },
      destination: "Holophoner Room",
      descriptions: {
        look: "A tall archway surrounded with elaborately carved symbols leads to the Holophoner Room.  ",
        listing:
          "south through the carven archway to the Holophoner Room",
        travel: "As {we} pass through the arch leading to the Holophoner Room, {we} take special notice of the symbols carved around the arch. ",
      },
    });
    

    The results would look like this in-game.

    Piano Room
    The tiny room is dominated by a grand piano.
    You can go east to the Cello Room, west to the Viola Room, north to the Tuba Room, or south through the carven archway to the Holophoner Room.