Skip to content

Modifying Existing Commands

ThePix edited this page Nov 1, 2022 · 4 revisions

There may be times you want to use a built-in command, but in a different way. One approach is to just create a new one, and give it a high "score" value so it takes priority. As long as the regular expression is the same, all should be good.

This page, however, is about tweaking existing commands. It is currently a work in progress; I will add to it as new examples occur to me.

General approach

What you need to do is to grab the command, and then change it how you like. Use the findCmd command to find it.

const cmd = findCmd('MetaHelp')

As you will see in the examples below, you often do not need to create a new variable - just modify the result returned from findCmd directly.

A new script

The most obvious way to change a command is to give it a new script.

findCmd('MetaHelp').script = function() {
  metamsg("You don't need help...")
}

Breaking the rules

Some commands have some rules set to do some standard filtering. Just occasionally they get in the way. For example, the EAT command has a rule saying the item must be held. If you have a plate of food, you might want the plate to be on the table, but still allow the player to eat it.

Just remove the rules.

findCmd('Eat').rules = []

Bear in mind that it does this for everything, so now the apple can be eaten whilst it is still on the tree.

Extending the scope

Let us suppose the player has access to a phone. We have a PHONE command, and once the NPC has picked up, the user can do TALK TO. The problem is that Quest will not find the NPC, because she is not here. We need to modify the scope to include the NPC on the phone.

This example assumes the name of the NPC on the phone is stored in the "onPhone" attribute of the player.

findCmd('TalkTo').objects[0].scope = function(item) {
  if (item.name === game.player.onPhone) return true
  return item.isAtLoc(game.player.loc, world.PARSER) && (item.npc || item.player);
}

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