Template: CONSULTABLE - ThePix/QuestJS GitHub Wiki

A consultable is an item the player can consult, that is, she can ASK the item ABOUT various topics.

The most common type of consultable is an NPC, and this template is included in the NPC template. The documentation for that goes though how to set up a CONSULTABLE, and will not be repeated here - I would strongly suggest reading that.

Here is a simple example, with one entry plus a default.

createItem("computer", CONSULTABLE(), {
  loc:'office',
  examine:'A recent Dell desktop, with a 24" screen.',
  askOptions:[
    {
      regex:/house/,
      msg:'You look "house" in Wiki, and find it is a type of building people live in. Who knew?',
    },
    {
      msg:"You find nothing on the computer about that.",
      failed:true,
    }
  ],  
})

The second example is more complicated.

  • The console will be in any room that has "console" set to true
  • The player needs a password (more specifically needs "hasPassword" to be true)
  • It will describe the player logging on and getting automatically logged off.
  • The text will be displayed using the "console" CSS class (set up in style.css)
createItem("computer", CONSULTABLE(), {
  isAtLoc:function(loc) { return typeof loc === 'string' ? w[loc].console : loc.console },
  examine:'A standard Yero console; anyone can consult it.',
  loggedOn:0,
  eventPeriod:1,
  eventActive:true,
  eventScript:function() {
    this.loggedOn--
    if (this.loggedOn === 0) msg("You are automatically logged off the console.")
  },
  testTalk:function() {
    if (!player.hasPassword) return falsemsg("You need a password to use the console")
    if (this.loggedOn < 1) msg("You log into the console.")
    this.loggedOn = 2
    return true
  },
  msg:function(s) {
    msg(s, {}, 'console')
  },
  askOptions:[
    {
      regex:/house/,
      msg:'House: A type of building people live in.',
    },
    {
      msg:"No data.",
      failed:true,
    }
  ],  
})