Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0

Class:Verb

Defined in: adventure/dictionary/Verb.js, line 5

Verb is the base class for all Verb instances. adventurejs comes with over 100 predefined Verbs, each with logic to support all of the predefined Asset classes. You can get pretty far using the predefined Verbs and Assets. Naturally, you're going to have ideas that don't fit the predefined logic. adventurejs provides several methods to modify Verbs, which range in complexity from making small edits all the way up to writing new Verbs from scratch.

  • patchVerb() lets an author replace only selected properties and methods of any predefined Verb.
  • replaceVerb() lets an author completely replace any of the predefined Verbs.
  • combineVerbs() lets an author consolidate predefined Verbs. Some of the predefined Verbs exist to catch subtle distinctions that may not be necessary for your game. For instance, twist and turn are predefined as distinct Verbs. If you don't need that level of distinction, you can use combineVerbs to consolidate them.
  • disableVerbs() lets an author delete specified Verbs from their game's Dictionary. Useful when you don't want to support certain Verbs.
  • enableVerbs() lets an author re-enable Verbs that have been disabled.
  • disableAllVerbsBut() lets an author disable all but specified Verbs. Useful for creating a game with limited language.
  • createVerb() lets an author create a new Verb from scratch.
  • doVerb() lets an author call a Verb from custom code during runtime.

Examples:

// patchVerb()

MyGame.patchVerb({ name: "crawl", prettyname: "wriggle", // change prettyname });

//replaceVerb()

MyGame.replaceVerb( "xyzzy", { name: "xyzzy", prettyname: "xyzzy", synonyms: [], do: function( params ) { console.log( "verbs.do" ); var msg = "Clever xyzzy response!"; if(msg) this.game.print( msg, MyGame.input.output_class ); return params }, });

// combineVerbs()

MyGame.combineVerbs( [ "twist" ], "turn" );

// disableVerbs()

MyGame.disableVerbs( [ "lick", "eat" ] );

// enableVerbs()

MyGame.enableVerbs( [ "lick", "eat" ] );

// disableAllVerbsBut()

MyGame.disableAllVerbsBut( [ "look", "examine" ] );

// createVerb()

MyGame.createVerb({ name: "blab_about_noun1", prettyname: "blab about", verb_prep_noun: [ "blab about" ], // blab about thing verb_noun_prep_noun: [ "blab about" ], // blab person about thing doTry: function( input ) { [insert logic here] return true; }, doSuccess: function( input ) { [insert logic here] return true; }, });

// doVerb() (call during runtime)

return this.game.dictionary.doVerb("xyzzy");

For more information about creating Verbs or modifying Verbs, see Verb Subscriptions, Verb Phases, Verb Actions, Verb Anatomy, Verb Process, or Modify Verbs.

Private Constructor:

var foo = new adventurejs.Verb(game)

Parameters:

Inherited Overrides

Methods Collapse all  |  Expand all

agree()

Defined in: adventure/dictionary/Verb.js, line 2643

Return name of the verb taking into consideration third-person singular present tense for subjects using nonhuman / male / female pronouns (he/she/it) or proper name.
canBeIntransitive()

Defined in: adventure/dictionary/Verb.js, line 2380

Verb can be intransitive if it doesn't require a noun.
do()

Defined in: adventure/dictionary/Verb.js, line 1060

Verb.do is a coordinating method that sequences six other submethods in a series. In the case of Verb instances that can act on a collection of Assets in a single turn, Verb.do only fires once, but it loops through the Asset collection and calls each submethod for every Asset in the collection. The sequence is:

do -> The two key submethods are Verb.doTry and Verb.doSuccess. For most Verb instances, these two methods contain the bulk of the logic particular to this Verb. Verb.doTry determines whether a Verb can act on an Asset, and if it can't, prints an error message to Display. Verb.doSuccess applies the Verb to the Asset: updates the game state, assembles dynamic output, and prints the results to Display.

A Verb instance isn't required to use all of these methods. Some Verbs may bypass Verb.doTry because no special conditions are required to apply the Verb. Some specialized Verbs such as oops and undo override Verb.do entirely and don't use any submethods.

The other four submethods – Verb.doBeforeTry, Verb.doAfterTry, Verb.doBeforeSuccess, and Verb.doAfterSuccess – exist to provide optional hooks for authors to add custom interactions with individual Assets. For more information about Verb Actions and Verb Phases, see Verb Actions and Verb Phases.

And so, the first thing Verb.do does is to verify that each method exists on the Verb instance. If the submethod exists, it is called. Each submethod sends a return to Verb.do.

If the Verb is acting on a collection, a false return means that the Asset currently being acted on has responded in a way that blocks further parsing, and brings this turn to a halt. A null return means that the Asset currently being acted on has concluded its own parsing, but not in such a way as to block further parsing, and Verb.do moves on to the next Asset.
doSuccess()

Defined in: adventure/dictionary/Verb.js, line 1525

doSuccess typically contains all the code needed to apply this Verb to the specified Asset once it has successfully passed through all of our conditional logic. doBeforeSuccess and doAfterSuccess are provided so that authors can apply custom success code on an item-by-item basis, but it is also possible to globally modify doSuccess. For information about modifying verbs, see Modify Verbs.
doTry()

Defined in: adventure/dictionary/Verb.js, line 1251

doTry typically contains all the specific logic needed to determine if this Verb can act on the specified Asset. (We already applied some general logic supplied by NounMustBe before arriving here.) For information about modifying verbs, see Modify Verbs.
enqueueCollection()

Defined in: adventure/dictionary/Verb.js, line 2045

enqueueCollection takes a collection of Assets and enqueues them to game.parser for sequential handling.
getState()

Defined in: adventure/dictionary/Verb.js, line 2398

Get this verb's state or unstate.
handleActions()

Defined in: adventure/dictionary/Verb.js, line 1266

handleActions attempts to call any verb actions that match the current assets and sentence structure.
handleFailure()

Defined in: adventure/dictionary/Verb.js, line 2089

handleFailure prints either a given fail message or a generic fail msg if one is specified.
handleSuccess()

Defined in: adventure/dictionary/Verb.js, line 2188

handleSuccess prints the provided success message or a generic one that has been defined by author. It also checks direct and indirect objects for custom verb subscription on_success results and tryDestroy results.
hasState()

Defined in: adventure/dictionary/Verb.js, line 2389

Does this verb have state or unstate?
hasStructure() → {boolean}

Defined in: adventure/dictionary/Verb.js, line 2416

Test if this verb supports the given sentence structure.

Returns:

boolean
hasVerbSubscriptionConnection()

Defined in: adventure/dictionary/Verb.js, line 2546

Test whether two assets are connected by this verb, for example a rope tied to a tree, or a computer plugged into a socket.
initialize()

Defined in: adventure/dictionary/Verb.js, line 2016

Todos: How does patchVerb handle initialization?

If Verb is a direction, initialize adds it to game.dictionary.direction_lookup.
set(props) → {adventurejs.Verb}

Defined in: adventure/dictionary/Verb.js, line 2077

Parameters:

  • props Object
    A generic object containing properties to copy to the DisplayObject instance.
Provides a chainable shortcut method for setting a number of properties on the instance.

Returns:

adventurejs.Verb Returns the instance the method is called on (useful for chaining calls.)
setState()

Defined in: adventure/dictionary/Verb.js, line 2407

Apply this verb's state or unstate to an asset.
setVerbConnection()

Defined in: adventure/dictionary/Verb.js, line 2426

Connect two assets that share a connection when acted upon by this verb. For example, in the case of 'plug computer into socket', each asset has the other asset's ID saved like this:

computer.is.connected_by.plugIn.to_iov = ['socket']
socket.is.connected_by.plugIn.to_dov = ['computer']
tryDestroyAfterUsing(object_of, asset) → {Object}

Defined in: adventure/asset/tryDestroyAfterUsing.js, line 6

Parameters:

  • object_of String
  • asset Object
tryDestroyAfterUsing is the underlying function for tryDestroyDirectObjectAfterUsing and tryDestroyIndirectObjectAfterUsing.

Returns:

Object
tryDestroyDirectObjectAfterUsing(asset) → {Boolean|string}

Defined in: adventure/asset/tryDestroyDirectObjectAfterUsing.js, line 6

Parameters:

  • asset Object
tryDestroyDirectObjectAfterUsing checks to see if the specified asset can only be used directly once with this verb by checking for asset.dov[this.name].then_destroy. This is intended to provide a hook for authors to easily destroy an object after a single use, such as a key that only works once and then breaks or disappears.

Returns:

Boolean | string
tryDestroyIndirectObjectAfterUsing(asset) → {Boolean|string}

Defined in: adventure/asset/tryDestroyIndirectObjectAfterUsing.js, line 6

Parameters:

  • asset Object
tryDestroyIndirectObjectAfterUsing checks to see if the specified asset can only be used indirectly once with this verb by checking for asset.iov[this.name].then_destroy. This is intended to provide a hook for authors to easily destroy an object after a single use, such as a key that only works once and then breaks or disappears.

Returns:

Boolean | string
tryToInferIndirectObject(direct_object, handle_input) → {Object}

Defined in: adventure/dictionary/Verb.js, line 1586

Parameters:

  • direct_object Object
  • handle_input Boolean
    If true, updates the global input object per standard specs used by most (but not all) of the verb instances that call this method.
tryToInferIndirectObject is called by some verbs when they receive a direct object with no indirect object, to test whether an indirect object can be inferred. The classic example is "unlock door" where the key must be inferred. In order to be inferred, indirect object must be in player inventory. If player hasn't already interacted with direct object and game.settings.infer_objects_after_first_use is true, tryToInferIndirectObject will fail regardless of other circumstances. The function only returns one indirect preposition: with. As in, "unlock door with key" or "feed pony with hay".

Returns:

Object
tryToPutThisInThatAspect(direct_object, preposition, indirect_object) → {Object}

Defined in: adventure/dictionary/Verb.js, line 1796

Parameters:

  • direct_object Object
  • preposition String
  • indirect_object Object
tryToPutThisInThatAspect checks to see if one asset can be placed within the specified aspect of another specified asset. For example, "put sword in stone" and "push stone into depression" would both be tested with this function.

Returns:

Object
unsetVerbConnection()

Defined in: adventure/dictionary/Verb.js, line 2487

Disconnect two assets that share a connection when acted upon by this verb. For example, in the case of 'plug computer into socket', each asset has the other asset's ID saved like this:

computer.is.connected_by.plugIn.to_iov = ['socket']
socket.is.connected_by.plugIn.to_dov = ['computer']
validate()

Properties  | 

accepts_adverbs :Array

Defined in: adventure/dictionary/Verb.js, line 432

Default value: []

accepts_direction :String

Defined in: adventure/dictionary/Phrase.js, line 26

Currently unused.
accepts_number :String

Defined in: adventure/dictionary/Phrase.js, line 40

Currently unused.
accepts_string :String

Defined in: adventure/dictionary/Phrase.js, line 19

Currently unused.
accepts_structures :Array

Defined in: adventure/dictionary/Verb.js, line 426

Default value: []

adjectives :String

Defined in: adventure/dictionary/Verb.js, line 299

Verb.adjective is for direction verbs so that, for example, 'south' can be described as 'southerly'.
adjectives :String

Defined in: adventure/dictionary/Verb.js, line 307

Verb.adjectives are for direction verbs so that, for example, the parser can associate accept words like 'southern' and 'southernly'.
article :Boolean

Defined in: adventure/dictionary/Verb.js, line 388

Default value: false

Set whether a direction can be referred to with an article, as in "there is a door to the north" vs "there is a door to starboard". This is a bit of mixed purpose because this property doesn't apply to the verb, but is stored in direction_lookup for reference with directions.
can_span :String

Defined in: adventure/dictionary/Verb.js, line 236

Locomotion verbs (ones that move the player) may result in player moving from object A to object B. When that occurs, output may vary depending on whether player would logically climb down off object A before climbing on object B, vs directly spanning the gap from object A to object B.
default_direction :String

Defined in: adventure/dictionary/Verb.js, line 163

Default value: ""

Some locomotion verbs supplied without a preposition may use a default direction, for instance climb + up.
dictionary :Object

Defined in: adventure/dictionary/Verb.js, line 143

Default value: {}

A shortcut to the main Game Dictionary.
direction_preposition :Boolean

Defined in: adventure/dictionary/Verb.js, line 400

Default value: ""

When player travels, this string may be prepended before the verb name, such as "you walk to the north"
doVerb :Getter

Defined in: adventure/dictionary/Verb.js, line 579

Returns "do[Verb]This" for consistency with callAction()
doVerbFromThis :Getter

Defined in: adventure/dictionary/Verb.js, line 595

Returns "do[Verb]FromThis" for consistency with callAction()
doVerbThatFromThis :Getter

Defined in: adventure/dictionary/Verb.js, line 635

Returns "do[Verb]ThatFromThis" for consistency with callAction()
doVerbThatWithThis :Getter

Defined in: adventure/dictionary/Verb.js, line 619

Returns "do[Verb]ThatWithThis" for consistency with callAction()
doVerbThis :Getter

Defined in: adventure/dictionary/Verb.js, line 587

Returns "do[Verb]This" for consistency with callAction()
doVerbThisFromThat :Getter

Defined in: adventure/dictionary/Verb.js, line 627

Returns "do[Verb]ThisFromThat" for consistency with callAction()
doVerbThisWithThat :Getter

Defined in: adventure/dictionary/Verb.js, line 611

Returns "do[Verb]ThisWithThat" for consistency with callAction()
doVerbWithThis :Getter

Defined in: adventure/dictionary/Verb.js, line 603

Returns "do[Verb]WithThis" for consistency with callAction()
enqueue_collections :Array

Defined in: adventure/dictionary/Verb.js, line 487

Default value: false

enqueue_collections if true allows a verb to unbundle the members of a collection in order to queue up separate actions for each. For example, "gems" is a collection that refers to three unique assets; "diamond", "emerald" and "ruby". If take.enqueue_collections is true, "take gems" will act individually on the diamond, the emerald and the ruby. Only applies to direct object.
extends :String

Defined in: adventure/dictionary/Verb.js, line 171

Default value: ""

Extension verbs may perform some contextual logic before forwarding to another verb for the bulk of logic, such as "crawl" -> "go".
game :Object

Defined in: adventure/dictionary/Verb.js, line 136

Default value: {}

A reference back to the main Game object.
gerund :String

Defined in: adventure/dictionary/Verb.js, line 200

The gerund of the verb. May be used in output strings.
in_can_mean_on :Boolean

Defined in: adventure/dictionary/Verb.js, line 355

Default value: false

Some types of objects can accept 'in' for 'on' interchangeably, such as 'sit in chair' / 'sit on chair', or 'lie in bed' / 'lie on bed'.
input_substitutions :Object

Defined in: adventure/dictionary/Verb.js, line 438

Default value: {}

To simplify identifying verbs in input, specifically with regards to adverbs & prepositions, we can provide a list of synonyms for the verb. The parser will look for these synonyms in the input and replace them with the verb name. Then, the verb can handle the adverb/preposition as it sees fit.
is_compass_direction :Boolean

Defined in: adventure/dictionary/Verb.js, line 371

Default value: false

Set whether direction verb is a compass direction, meaning, it can be found on a compass rose.
is_direction :Boolean

Defined in: adventure/dictionary/Verb.js, line 364

Default value: false

Set whether verb is a direction verb.
is_relative_direction :Boolean

Defined in: adventure/dictionary/Verb.js, line 379

Default value: false

Set whether direction verb is a relative direction such as those used on ships: port, starboard, etc. Also applies to left, right, forward, back, etc.
let_verb_handle_disambiguation :Boolean

Defined in: adventure/dictionary/Verb.js, line 335

Default value: false

Setting this to true allows you to write your own disambiguation script. Warning: going off road! Recommended for experienced Javascript users.
let_verb_handle_remaining_input :Boolean

Defined in: adventure/dictionary/Verb.js, line 344

Default value: false

When input is parsed, parse the verb and then pass the remainder of the input to the verb as a string, for the verb to act on. Chief example is: "oops xxx" where we don't want to parse xxx, we just want to let oops use it as a substitute for last turn's unknown input.
name :String

Defined in: adventure/dictionary/Verb.js, line 179

Default value: ""

String provided in Verb definition file (aka preverb).
Name :Getter

Defined in: adventure/dictionary/Verb.js, line 503

Default value: []

Return uppercase name of the verb.
override_verb_failure_msg :String

Defined in: adventure/dictionary/Verb.js, line 450

Default value: undefined

Provides a simple method for an author to override all failure messages for a verb with one generic string.
override_verb_success_msg :String

Defined in: adventure/dictionary/Verb.js, line 459

Default value: undefined

Provides a simple method for an author to override success messages for a verb with one generic string.
past_tense :String

Defined in: adventure/dictionary/Verb.js, line 194

The past tense of the verb. May be used in output strings.
phrase1 :Object

Defined in: adventure/dictionary/Verb.js, line 408

Default value: {}

phrase2 :Object

Defined in: adventure/dictionary/Verb.js, line 414

Default value: {}

phrase3 :Object

Defined in: adventure/dictionary/Verb.js, line 420

Default value: {}

posture :String

Defined in: adventure/dictionary/Verb.js, line 206

Set a preferred posture that results when this verb acts on player. asset.aspect.aspect.nest.posture takes precedence unless this.override_aspect_posture = true.
posture :String

Defined in: adventure/dictionary/Verb.js, line 214

When applying this verb to player, try to override any posture setting found in the player's container at asset.aspects.aspect.nest.posture. (Not guaranteed to work as there's currently very little verb logic that supports this setting.)
prettyname :String

Defined in: adventure/dictionary/Verb.js, line 186

String provided in verb definition file. The prettyname is used for printing, and can include spaces, ie ask prints as "ask about".
requires_number :String

Defined in: adventure/dictionary/Phrase.js, line 47

Currently unused.
requires_string :String

Defined in: adventure/dictionary/Phrase.js, line 33

Currently unused.
state :String

Defined in: adventure/dictionary/Verb.js, line 247

state is an optional property for verbs that apply state to assets, such as close and lock. For example, "close door" will set door.is.closed to true. When used, state will contain the state to be set true on an asset. In the case of close, its state would be "closed".
state_strings :String

Defined in: adventure/dictionary/Verb.js, line 267

state_strings is an optional property for verbs that is used to provide string substitutions for authors using the string substitution form of $(sink drain is| plugged or| unplugged). Because "unplugged" isn't a proper verb state, we'll use this as a reverse lookup to test whether the asset, sink_drain in this case, is subscribed to the relevant verb and has the specified state. state_strings only apply to direct objects.
subject_must_be :Object

Defined in: adventure/dictionary/Verb.js, line 315

Default value: {}

subject_must_be sets conditions that the subject must meet in order for the Verb to act upon it. player: true is set by default. In order to allow player to instruct an NPC to perform a verb such as "Floyd, go east", that verb must be set player: false.
synonyms :Getter/Setter

Defined in: adventure/dictionary/Verb.js, line 643

Default value: []

synonyms provide alternate words for verbs, such as "get" for "take".
tryVerbFromThis :Getter

Defined in: adventure/dictionary/Verb.js, line 539

Returns "try[Verb]FromThis" for consistency with callAction()
tryVerbThatFromThis :Getter

Defined in: adventure/dictionary/Verb.js, line 571

Returns "try[Verb]ThatFromThis" for consistency with callAction()
tryVerbThatWithThis :Getter

Defined in: adventure/dictionary/Verb.js, line 555

Returns "try[Verb]ThatWithThis" for consistency with callAction()
tryVerbThis :Getter

Defined in: adventure/dictionary/Verb.js, line 523

Returns "try[Verb]This" for consistency with callAction()
tryVerbThisFromThat :Getter

Defined in: adventure/dictionary/Verb.js, line 563

Returns "try[Verb]ThisFromThat" for consistency with callAction()
tryVerbThisWithThat :Getter

Defined in: adventure/dictionary/Verb.js, line 547

Returns "try[Verb]ThisWithThat" for consistency with callAction()
tryVerbWithThis :Getter

Defined in: adventure/dictionary/Verb.js, line 531

Returns "try[Verb]WithThis" for consistency with callAction()
type :String

Defined in: adventure/dictionary/Verb.js, line 151

Default value: ""

May be used to help narrow verb selections in ambiguous situations.
unstate :String

Defined in: adventure/dictionary/Verb.js, line 257

unstate is an optional property for verbs that unset state from assets, such as open and unlock. For example, "open door" will set door.is.closed to false. When used, unstate will contain the state to be set false on an asset. In the case of open, its unstate would be "closed".
verb_noun_prep :Array

Defined in: adventure/dictionary/Verb.js, line 709

Default value: []

For verb/noun pairs with a trailing preposition, or more likely a direction, such as "push bed north". When player input is parsed, they'll be concatenated, eg to "pushnorth bed".
verb_noun_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 873

Default value: []

For verb/preposition pairs separated by another word, usually a noun, such as "lock door with key" or "take sword from stone". When player input is parsed, they'll be concatenated, eg to "lockwith door key" or "takefrom sword stone".

Though verb_prep_noun and verb_noun_prep_noun look similar, the reason they are separate fields is because we have to use different regex patterns to find each type in user input.
verb_noun_prep_noun_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 962

Default value: []

For a verb phrase with three nouns and two prepositions. For example, in the phrase "tie boat to pier with rope", we're looking for "tie" and "to" and "with", and we would parse the phrase as "tietowith boat pier rope"
verb_noun_prep_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 920

Default value: []

For a verb phrase with two nouns and two prepositions. For example, in the phrase "take skateboard from under bed", we're looking for "take" and "from" and "under", and we would parse the phrase as "takefromunder skateboard bed"
verb_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 750

Default value: []

For verb/preposition pairs separated by a space, such as "go to" or "look at". When player input is parsed, they'll be concatenated, eg "go to" to "goTo".
verb_prep_noun_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 667

Default value: []

For phrases like "jump from branch to vine" or "look at sun with glasses", where we have a verb + preposition followed by a noun and then another preposition
verb_prep_noun_prep_noun_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 1008

Default value: []

For a verb phrase with three nouns and three prepositions. For example, in the phrase "swing from branch to tree on vine", we're looking for "swing from with on".
verb_prep_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 791

Default value: []

For compound preps separated by spaces, verb/prep/prep, such as "get out of"
verb_prep_prep_prep_noun :Array

Defined in: adventure/dictionary/Verb.js, line 832

Default value: []

For three part compound preps, verb/prep/prep/prep, such as "get out from behind"