Template: EXIT_FAKER - ThePix/QuestJS GitHub Wiki

An EXIT_FAKER is a type of location, one that does not have proper exits. Instead it has a bunch of other attributes that are used to fake real exits during play. The big advantage of that is that those other attributes will be saved. This means you can create exits on the fly.

The only time I would advocate doing that is when you want to create rooms during a game. If you just want a specific exit to appear or disappear during the course of a game, a better technique is just to hidden the exit when it is not there.

With that in mind, it ay be useful to review how to create items on the fly. The basic strategy is to create a prototype, to clone it, and then change the clone as required.

Before we get to cloning, here is a very simple room using EXIT_FAKER.

createRoom('library', EXIT_FAKER(), {
  desc:'It is full of books.',
  
  exit_south:'hall',
})

Instead of Exit objects as attributes, it uses strings, and the name has to be prefixed "exit_". You can add attributes to exits by inserting the attribute name, "exit_[attribute]_[direction]", though you are limited to a redefined set of attributes:

  • locked
  • hidden
  • scenery
  • msg
  • npcLeaveMsg
  • npcEnterMsg
  • func

The first three are Booleans, and in fact are identical to normal exit attributes, which are always on the room, not the exit. The next three are strings, and will (in effect) be added to the Exit object. The last, "func", is a string that names a function attribute on the room.

Here is a more involved example to illustrate:

createRoom('library', EXIT_FAKER(), {
  desc:'It is full of books.',
  
  myFunc:function(char) {
    char.msg(lang.stop_posture(char))
    if (w.hall.state === 1) {
      msg("You slip out the door to the hall quietly.")
    }
    else {
      msg("You head south.")
    }
    char.moveChar(this)
    return true
  },

  exit_south:'hall',
  exit_msg_south:'Back to the hall, you trot.',

  exit_east:'study',
  exit_locked_east:true,
  exit_func_east:'myFunc',
})