Class: Verb
Defined in: adventure/dictionary/Verb.js, line 6
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)
this.game.dictionary.doVerb("xyzzy");
For more information about creating Verbs or modifying Verbs, see How to Use Verb Subscriptions, How to Use Verb Phase Hooks, How to Use Verb Event Hooks, Verb Anatomy, Verb Process, or How to Modify Verbs.
Private Constructor:
var foo = new adventurejs.Verb(game)
Parameters:
-
game
adventurejs.Game
A reference to the game instance.
Index
Methods:
- canBeIntransitive
- do
- doAfterSuccess
- doAfterTry
- doBeforeSuccess
- doBeforeTry
- doSuccess
- doTry
- enqueueCollection
- getState
- handleFailure
- handleSuccess
- hasState
- hasVerbSubscriptionConnection
- initialize
- set
- setVerbSubscriptionConnection
- tryDestroyAfterUsing
- tryDestroyDirectObjectAfterUsing
- tryDestroyIndirectObjectAfterUsing
- tryPlaceAssetInAspectOfAsset
- tryToInferIndirectObject
- unsetVerbSubscriptionConnection
- validate
Properties:
- accepts_direction
- accepts_number
- accepts_string
- adjectives
- dictionary
- direction_preposition
- game
- 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
- onDoFromThis
- onDoThatFromThis
- onDoThatWithThis
- onDoThis
- onDoThisFromThat
- onDoThisWithThat
- onDoWithThis
- onTryFromThis
- onTryThatFromThis
- onTryThatWithThis
- onTryThis
- onTryThisFromThat
- onTryThisWithThat
- onTryWithThis
- override_verb_failure_msg
- override_verb_success_msg
- past_tense
- player_must_be
- prettyname
- related
- requires_number
- requires_string
- state
- state_strings
- synonyms
- 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 |
Defined in: adventure/dictionary/Verb.js, line 1993
Defined in: adventure/dictionary/Verb.js, line 1022
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 Event Hooks and Verb Phase Hooks, see How to Use Verb Event Hooks and How to Use Verb Phase Hooks.
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.
Defined in: adventure/dictionary/Verb.js, line 1369
Defined in: adventure/dictionary/Verb.js, line 1253
Defined in: adventure/dictionary/Verb.js, line 1304
Defined in: adventure/dictionary/Verb.js, line 1188
Defined in: adventure/dictionary/Verb.js, line 1351
Defined in: adventure/dictionary/Verb.js, line 1236
Defined in: adventure/dictionary/Verb.js, line 1716
Defined in: adventure/dictionary/Verb.js, line 1760
Defined in: adventure/dictionary/Verb.js, line 1839
Defined in: adventure/dictionary/Verb.js, line 2004
Defined in: adventure/dictionary/Verb.js, line 2115
Defined in: adventure/dictionary/Verb.js, line 1673
Todos: How does patchVerb handle initialization?
Defined in: adventure/dictionary/Verb.js, line 1747
Parameters:
-
props
Object
A generic object containing properties to copy to the DisplayObject instance.
Defined in: adventure/dictionary/Verb.js, line 2024
computer.is.direct_object_of_verb.plugIn.with_params.connections = ['socket']
socket.is.indirect_object_of_verb.plugIn.with_params.connections = ['computer']
This is one of two verb subscription properties that are related and very similar, and it's important to understand the distinction between them.
...with_assets
defines which assets CAN BE connected.
...with_params.connections
stores which assets ARE connected.
with_assets:
computer.is.direct_object_of_verb.plugIn.with_assets = ['socket']
connections:
computer.is.direct_object_of_verb.plugIn.with_params.connections = ['socket']
Defined in: adventure/asset/tryDestroyAfterUsing.js, line 7
Parameters:
-
object_of
String -
asset
Object
Returns:
Object
Defined in: adventure/asset/tryDestroyDirectObjectAfterUsing.js, line 7
Parameters:
-
asset
Object
asset.is.direct_object_of_verb[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
Defined in: adventure/asset/tryDestroyIndirectObjectAfterUsing.js, line 7
Parameters:
-
asset
Object
asset.is.indirect_object_of_verb[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
Defined in: adventure/dictionary/Verb.js, line 1465
Parameters:
-
direct_object
Object -
preposition
String -
indirect_object
Object
Returns:
Object
Defined in: adventure/dictionary/Verb.js, line 1411
Parameters:
-
direct_object
Object
Returns:
Object
Defined in: adventure/dictionary/Verb.js, line 2077
computer.is.direct_object_of_verb.plugIn.with_params.connections = ['socket']
socket.is.indirect_object_of_verb.plugIn.with_params.connections = ['computer']
Properties Collapse all |
Defined in: adventure/dictionary/Verb.js, line 231
Defined in: adventure/dictionary/Verb.js, line 144
Default value: {}
Defined in: adventure/dictionary/Verb.js, line 309
Default value: ""
Defined in: adventure/dictionary/Verb.js, line 137
Default value: {}
Defined in: adventure/dictionary/Verb.js, line 276
Default value: false
Defined in: adventure/dictionary/Verb.js, line 326
Default value: {}
Defined in: adventure/dictionary/Verb.js, line 292
Default value: false
Defined in: adventure/dictionary/Verb.js, line 285
Default value: false
Defined in: adventure/dictionary/Verb.js, line 300
Default value: false
Defined in: adventure/dictionary/Verb.js, line 256
Default value: false
Defined in: adventure/dictionary/Verb.js, line 265
Default value: false
Defined in: adventure/dictionary/Verb.js, line 152
Default value: ""
Defined in: adventure/dictionary/Verb.js, line 376
Default value: []
Defined in: adventure/dictionary/Verb.js, line 442
Defined in: adventure/dictionary/Verb.js, line 477
Defined in: adventure/dictionary/Verb.js, line 463
Defined in: adventure/dictionary/Verb.js, line 435
Defined in: adventure/dictionary/Verb.js, line 470
Defined in: adventure/dictionary/Verb.js, line 456
Defined in: adventure/dictionary/Verb.js, line 449
Defined in: adventure/dictionary/Verb.js, line 398
Defined in: adventure/dictionary/Verb.js, line 426
Defined in: adventure/dictionary/Verb.js, line 412
Defined in: adventure/dictionary/Verb.js, line 384
Defined in: adventure/dictionary/Verb.js, line 419
Defined in: adventure/dictionary/Verb.js, line 405
Defined in: adventure/dictionary/Verb.js, line 391
Defined in: adventure/dictionary/Verb.js, line 345
Default value: undefined
Defined in: adventure/dictionary/Verb.js, line 354
Default value: undefined
Defined in: adventure/dictionary/Verb.js, line 171
Defined in: adventure/dictionary/Verb.js, line 239
Default value: {}
Defined in: adventure/dictionary/Verb.js, line 162
Defined in: adventure/dictionary/Verb.js, line 178
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".
Defined in: adventure/dictionary/Verb.js, line 198
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.
Defined in: adventure/dictionary/Verb.js, line 485
Default value: []
Defined in: adventure/dictionary/Verb.js, line 188
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".
Defined in: adventure/dictionary/Verb.js, line 567
Default value: []
Defined in: adventure/dictionary/Verb.js, line 773
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.
Defined in: adventure/dictionary/Verb.js, line 883
Default value: []
Defined in: adventure/dictionary/Verb.js, line 830
Default value: []
Defined in: adventure/dictionary/Verb.js, line 620
Default value: []
Defined in: adventure/dictionary/Verb.js, line 517
Default value: []
Defined in: adventure/dictionary/Verb.js, line 936
Default value: []
Defined in: adventure/dictionary/Verb.js, line 673
Default value: []
Defined in: adventure/dictionary/Verb.js, line 723
Default value: []