Skip to content

Quick Commands

ThePix edited this page Mar 1, 2022 · 3 revisions

Most commands are very similar, except for the verb itself, with all the work done in the item. QuestJS offers a short cut to quickly create such commands.

This is somewhat language dependant, so is in lang-en.js

Here is a simple example:

lang.createVerb('Kick')

This gives you a command called "Kick" that will match, for example, KICK MACHINE, and call the "kick" attribute on the item,

Sometime you might want to include other options, these can be added as a dictionary. It you want to add synonyms, include a "words" option, a string with each variation separated by a vertical bar. If the verb has an unusual "ing" form, set the "ing" option. If the item is expected to be held, set "held" to true.

lang.createVerb('Roll', {words:'roll up|roll'})
lang.createVerb('Shake', {ing:'Shaking', held:true})

It the item does not have the right attribute, Quest will give a default message; "Kicking the machine is not going to achieve anything." You can set "defmsg" to a custom string, or set it to true and Quest will say "The machine is not something you can do that with."

With or Using

You can create two item commands too, using the form USING (and some variations). The options are generally the same. Note that item2 is assumed to be held - you have no option to change it.

lang.createVerbWith("Slice", {held:true, ing:'Slicing'})

The command in this case will be "SliceWith" but the attribute on item1 will be "slice". This allows you to use the same attribute for both. The function will be passed a dictionary, with "with" set to the second item, if applicable.

createItem("carrot", TAKEABLE(), {
  examine:"It's a carrot!",
  slice:function(options) {
    if (options.with === undefined) {
      if (w.knife.loc !== player.name) {
        return falsemsg("Going to need a knife to do that.")
      }
    }
    else if (options.with !== w.knife) {
      return falsemsg("You can't cut a carrot with {nm:with:the}.", {with:options.with})
    }
    // do stuff
    msg('Done.')
    return true
  },
})

Tutorial

QuestJS Basics

The Text Processor

Commands

Templates for Items

See also:

Handing NPCs

The User Experience (UI)

The main screen

The Side Panes

Multi-media (sounds, images, maps, etc.)

Dialogue boxes

Other Elements

Role-playing Games

Web Basics

How-to

Time

Items

Locations

Exits

Meta

Meta: About The Whole Game

Releasing Your Game

Reference

Clone this wiki locally