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
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
- tryToInferIndirectObject
- tryToPutThisInThatAspect
- unsetVerbConnection
- validate
Properties:
- accepts_adverbs
- accepts_direction
- accepts_number
- accepts_string
- accepts_structures
- adjectives
- adjectives
- 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()
Defined in: adventure/dictionary/Verb.js, line 2643
canBeIntransitive()
Defined in: adventure/dictionary/Verb.js, line 2380
do()
Defined in: adventure/dictionary/Verb.js, line 1060
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()
Defined in: adventure/dictionary/Verb.js, line 1525
doTry()
Defined in: adventure/dictionary/Verb.js, line 1251
enqueueCollection()
Defined in: adventure/dictionary/Verb.js, line 2045
getState()
Defined in: adventure/dictionary/Verb.js, line 2398
handleActions()
Defined in: adventure/dictionary/Verb.js, line 1266
handleFailure()
Defined in: adventure/dictionary/Verb.js, line 2089
handleSuccess()
Defined in: adventure/dictionary/Verb.js, line 2188
hasState()
Defined in: adventure/dictionary/Verb.js, line 2389
hasStructure() → {boolean}
Defined in: adventure/dictionary/Verb.js, line 2416
Returns:
boolean
hasVerbSubscriptionConnection()
Defined in: adventure/dictionary/Verb.js, line 2546
initialize()
Defined in: adventure/dictionary/Verb.js, line 2016
Todos: How does patchVerb handle initialization?
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.
setState()
Defined in: adventure/dictionary/Verb.js, line 2407
setVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 2426
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
Returns:
Object
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(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
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.
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
Returns:
Object
unsetVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 2487
computer.is.connected_by.plugIn.to_iov = ['socket']
socket.is.connected_by.plugIn.to_dov = ['computer']
validate()
Defined in: adventure/dictionary/Verb.js, line 2009
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
accepts_number :String
Defined in: adventure/dictionary/Phrase.js, line 40
accepts_string :String
Defined in: adventure/dictionary/Phrase.js, line 19
accepts_structures :Array
Defined in: adventure/dictionary/Verb.js, line 426
Default value: []
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 299
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 307
article :Boolean
Defined in: adventure/dictionary/Verb.js, line 388
Default value: false
can_span :String
Defined in: adventure/dictionary/Verb.js, line 236
default_direction :String
Defined in: adventure/dictionary/Verb.js, line 163
Default value: ""
dictionary :Object
Defined in: adventure/dictionary/Verb.js, line 143
Default value: {}
direction_preposition :Boolean
Defined in: adventure/dictionary/Verb.js, line 400
Default value: ""
doVerb :Getter
Defined in: adventure/dictionary/Verb.js, line 579
doVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 595
doVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 635
doVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 619
doVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 587
doVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 627
doVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 611
doVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 603
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: ""
game :Object
Defined in: adventure/dictionary/Verb.js, line 136
Default value: {}
gerund :String
Defined in: adventure/dictionary/Verb.js, line 200
in_can_mean_on :Boolean
Defined in: adventure/dictionary/Verb.js, line 355
Default value: false
input_substitutions :Object
Defined in: adventure/dictionary/Verb.js, line 438
Default value: {}
is_compass_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 371
Default value: false
is_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 364
Default value: false
is_relative_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 379
Default value: false
let_verb_handle_disambiguation :Boolean
Defined in: adventure/dictionary/Verb.js, line 335
Default value: false
let_verb_handle_remaining_input :Boolean
Defined in: adventure/dictionary/Verb.js, line 344
Default value: false
name :String
Defined in: adventure/dictionary/Verb.js, line 179
Default value: ""
Name :Getter
Defined in: adventure/dictionary/Verb.js, line 503
Default value: []
override_verb_failure_msg :String
Defined in: adventure/dictionary/Verb.js, line 450
Default value: undefined
override_verb_success_msg :String
Defined in: adventure/dictionary/Verb.js, line 459
Default value: undefined
past_tense :String
Defined in: adventure/dictionary/Verb.js, line 194
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
posture :String
Defined in: adventure/dictionary/Verb.js, line 214
prettyname :String
Defined in: adventure/dictionary/Verb.js, line 186
requires_number :String
Defined in: adventure/dictionary/Phrase.js, line 47
requires_string :String
Defined in: adventure/dictionary/Phrase.js, line 33
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: {}
synonyms :Getter/Setter
Defined in: adventure/dictionary/Verb.js, line 643
Default value: []
tryVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 539
tryVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 571
tryVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 555
tryVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 523
tryVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 563
tryVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 547
tryVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 531
type :String
Defined in: adventure/dictionary/Verb.js, line 151
Default value: ""
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: []
verb_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 873
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 :Array
Defined in: adventure/dictionary/Verb.js, line 962
Default value: []
verb_noun_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 920
Default value: []
verb_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 750
Default value: []
verb_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 667
Default value: []
verb_prep_noun_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1008
Default value: []
verb_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 791
Default value: []
verb_prep_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 832
Default value: []