Class:Verb
Defined in: adventure/dictionary/Verb.js, line 5
Description
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
andturn
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:
-
game
adventurejs.Game
A reference to the game instance.
- Index
- Methods
- Properties
Index
Methods:
- agree
- canBeIntransitive
- do
- doSuccess
- doTry
- enqueueCollection
- getState
- handleActions
- handleFailure
- handleSuccess
- hasState
- hasStructure
- hasVerbSubscriptionConnection
- initialize
- set
- setState
- setVerbConnection
- tryDestroyAfterUsing
- tryDestroyDirectObjectAfterUsing
- tryDestroyIndirectObjectAfterUsing
- tryPhaseHook
- tryToInferIndirectObject
- tryToPutThisInThatAspect
- unsetVerbConnection
- validate
Properties:
- accepts_adverbs
- accepts_direction
- accepts_number
- accepts_string
- accepts_structures
- adjectives
- adjectives
- allow_iov_on_iov
- article
- can_span
- default_direction
- dictionary
- direction_preposition
- doVerb
- doVerbFromThis
- doVerbThatFromThis
- doVerbThatWithThis
- doVerbThis
- doVerbThisFromThat
- doVerbThisWithThat
- doVerbWithThis
- enqueue_collections
- extends
- game
- gerund
- in_can_mean_on
- input_substitutions
- is_compass_direction
- is_direction
- is_relative_direction
- let_verb_handle_disambiguation
- let_verb_handle_remaining_input
- name
- Name
- override_verb_failure_msg
- override_verb_success_msg
- past_tense
- phrase1
- phrase2
- phrase3
- posture
- posture
- prettyname
- related
- requires_number
- requires_string
- state
- state_strings
- subject_must_be
- synonyms
- tryVerbFromThis
- tryVerbThatFromThis
- tryVerbThatWithThis
- tryVerbThis
- tryVerbThisFromThat
- tryVerbThisWithThat
- tryVerbWithThis
- type
- unstate
- verb_noun_prep
- verb_noun_prep_noun
- verb_noun_prep_noun_prep_noun
- verb_noun_prep_prep_noun
- verb_prep_noun
- verb_prep_noun_prep_noun
- verb_prep_noun_prep_noun_prep_noun
- verb_prep_prep_noun
- verb_prep_prep_prep_noun
Methods Collapse all |
agree
agree()
Defined in: adventure/dictionary/Verb.js, line 2895
canBeIntransitive
canBeIntransitive()
Defined in: adventure/dictionary/Verb.js, line 2631
do
do()
Defined in: adventure/dictionary/Verb.js, line 1077
do ->
- doBeforeTry (hook for authors)
- doTry
- doAfterTry (hook for authors)
- doBeforeSuccess (hook for authors)
- doSuccess
- doAfterSuccess (hook for authors)
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
doSuccess()
Defined in: adventure/dictionary/Verb.js, line 1729
doTry
doTry()
Defined in: adventure/dictionary/Verb.js, line 1343
enqueueCollection
enqueueCollection()
Defined in: adventure/dictionary/Verb.js, line 2295
getState
getState()
Defined in: adventure/dictionary/Verb.js, line 2649
handleActions
handleActions()
Defined in: adventure/dictionary/Verb.js, line 1358
handleFailure
handleFailure()
Defined in: adventure/dictionary/Verb.js, line 2339
handleSuccess
handleSuccess()
Defined in: adventure/dictionary/Verb.js, line 2438
hasState
hasState()
Defined in: adventure/dictionary/Verb.js, line 2640
hasStructure
hasStructure() → {boolean}
Defined in: adventure/dictionary/Verb.js, line 2667
Returns:
boolean
hasVerbSubscriptionConnection
hasVerbSubscriptionConnection()
Defined in: adventure/dictionary/Verb.js, line 2798
initialize
initialize()
Defined in: adventure/dictionary/Verb.js, line 2266
Todos: How does patchVerb handle initialization?
set
set(props) → {adventurejs.Verb}
Defined in: adventure/dictionary/Verb.js, line 2327
Parameters:
-
props
Object
A generic object containing properties to copy to the DisplayObject instance.
setState
setState()
Defined in: adventure/dictionary/Verb.js, line 2658
setVerbConnection
setVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 2677
computer.is.connected_by.plugIn.to_iov = ['socket']
socket.is.connected_by.plugIn.to_dov = ['computer']
tryDestroyAfterUsing
tryDestroyAfterUsing(object_of, asset) → {Object}
Defined in: adventure/asset/tryDestroyAfterUsing.js, line 6
Parameters:
-
object_of
String -
asset
Object
Returns:
Object
tryDestroyDirectObjectAfterUsing
tryDestroyDirectObjectAfterUsing(asset) → {Boolean|string}
Defined in: adventure/asset/tryDestroyDirectObjectAfterUsing.js, line 6
Parameters:
-
asset
Object
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
tryDestroyIndirectObjectAfterUsing(asset) → {Boolean|string}
Defined in: adventure/asset/tryDestroyIndirectObjectAfterUsing.js, line 6
Parameters:
-
asset
Object
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
tryPhaseHook
tryPhaseHook(phase) → {*}
tryToInferIndirectObject
tryToInferIndirectObject(options) → {Object}
Defined in: adventure/dictionary/Verb.js, line 1795
Parameters:
-
options
Object
An object of options.Properties
-
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. -
context
Object
The subject, usually player, could be an NPC. -
infer_first_use
Boolean
Optional param to set whether inference should work on first use.
-
Returns:
Object
tryToPutThisInThatAspect
tryToPutThisInThatAspect(direct_object, preposition, indirect_object) → {Object}
Defined in: adventure/dictionary/Verb.js, line 2012
Parameters:
-
direct_object
Object -
preposition
String -
indirect_object
Object
Returns:
Object
unsetVerbConnection
unsetVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 2738
computer.is.connected_by.plugIn.to_iov = ['socket']
socket.is.connected_by.plugIn.to_dov = ['computer']
validate
validate()
Defined in: adventure/dictionary/Verb.js, line 2259
Properties |
accepts_adverbs
accepts_adverbs :Array
Defined in: adventure/dictionary/Verb.js, line 432
Default value: []
accepts_direction
accepts_direction :String
Defined in: adventure/dictionary/Phrase.js, line 26
accepts_number
accepts_number :String
Defined in: adventure/dictionary/Phrase.js, line 40
accepts_string
accepts_string :String
Defined in: adventure/dictionary/Phrase.js, line 19
accepts_structures
accepts_structures :Array
Defined in: adventure/dictionary/Verb.js, line 426
Default value: []
adjectives
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 299
adjectives
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 307
allow_iov_on_iov
allow_iov_on_iov :Array
Defined in: adventure/dictionary/Verb.js, line 500
Default value: false
allow_iov_on_iov
allows for some
additional checking when querying whether a verb is allowed
to operate on a particular pair of assets.
article
article :Boolean
Defined in: adventure/dictionary/Verb.js, line 388
Default value: false
can_span
can_span :String
Defined in: adventure/dictionary/Verb.js, line 236
default_direction
default_direction :String
Defined in: adventure/dictionary/Verb.js, line 163
Default value: ""
dictionary
dictionary :Object
Defined in: adventure/dictionary/Verb.js, line 143
Default value: {}
direction_preposition
direction_preposition :Boolean
Defined in: adventure/dictionary/Verb.js, line 400
Default value: ""
doVerb
doVerb :Getter
Defined in: adventure/dictionary/Verb.js, line 596
doVerbFromThis
doVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 612
doVerbThatFromThis
doVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 652
doVerbThatWithThis
doVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 636
doVerbThis
doVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 604
doVerbThisFromThat
doVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 644
doVerbThisWithThat
doVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 628
doVerbWithThis
doVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 620
enqueue_collections
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
extends :String
Defined in: adventure/dictionary/Verb.js, line 171
Default value: ""
game
game :Object
Defined in: adventure/dictionary/Verb.js, line 136
Default value: {}
gerund
gerund :String
Defined in: adventure/dictionary/Verb.js, line 200
in_can_mean_on
in_can_mean_on :Boolean
Defined in: adventure/dictionary/Verb.js, line 355
Default value: false
input_substitutions
input_substitutions :Object
Defined in: adventure/dictionary/Verb.js, line 438
Default value: {}
is_compass_direction
is_compass_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 371
Default value: false
is_direction
is_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 364
Default value: false
is_relative_direction
is_relative_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 379
Default value: false
let_verb_handle_disambiguation
let_verb_handle_disambiguation :Boolean
Defined in: adventure/dictionary/Verb.js, line 335
Default value: false
let_verb_handle_remaining_input
let_verb_handle_remaining_input :Boolean
Defined in: adventure/dictionary/Verb.js, line 344
Default value: false
name
name :String
Defined in: adventure/dictionary/Verb.js, line 179
Default value: ""
Name
Name :Getter
Defined in: adventure/dictionary/Verb.js, line 520
Default value: []
override_verb_failure_msg
override_verb_failure_msg :String
Defined in: adventure/dictionary/Verb.js, line 450
Default value: undefined
override_verb_success_msg
override_verb_success_msg :String
Defined in: adventure/dictionary/Verb.js, line 459
Default value: undefined
past_tense
past_tense :String
Defined in: adventure/dictionary/Verb.js, line 194
phrase1
phrase1 :Object
Defined in: adventure/dictionary/Verb.js, line 408
Default value: {}
phrase2
phrase2 :Object
Defined in: adventure/dictionary/Verb.js, line 414
Default value: {}
phrase3
phrase3 :Object
Defined in: adventure/dictionary/Verb.js, line 420
Default value: {}
posture
posture :String
Defined in: adventure/dictionary/Verb.js, line 206
posture
posture :String
Defined in: adventure/dictionary/Verb.js, line 214
prettyname
prettyname :String
Defined in: adventure/dictionary/Verb.js, line 186
related
requires_number
requires_number :String
Defined in: adventure/dictionary/Phrase.js, line 47
requires_string
requires_string :String
Defined in: adventure/dictionary/Phrase.js, line 33
state
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
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
subject_must_be :Object
Defined in: adventure/dictionary/Verb.js, line 315
Default value: {}
synonyms
synonyms :Getter/Setter
Defined in: adventure/dictionary/Verb.js, line 660
Default value: []
tryVerbFromThis
tryVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 556
tryVerbThatFromThis
tryVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 588
tryVerbThatWithThis
tryVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 572
tryVerbThis
tryVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 540
tryVerbThisFromThat
tryVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 580
tryVerbThisWithThat
tryVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 564
tryVerbWithThis
tryVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 548
type
type :String
Defined in: adventure/dictionary/Verb.js, line 151
Default value: ""
unstate
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
verb_noun_prep :Array
Defined in: adventure/dictionary/Verb.js, line 726
Default value: []
verb_noun_prep_noun
verb_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 890
Default value: []
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
verb_noun_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 979
Default value: []
verb_noun_prep_prep_noun
verb_noun_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 937
Default value: []
verb_prep_noun
verb_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 767
Default value: []
verb_prep_noun_prep_noun
verb_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 684
Default value: []
verb_prep_noun_prep_noun_prep_noun
verb_prep_noun_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1025
Default value: []
verb_prep_prep_noun
verb_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 808
Default value: []
verb_prep_prep_prep_noun
verb_prep_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 849
Default value: []