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 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:
- canBeIntransitive
- do
- doSuccess
- doTry
- enqueueCollection
- getState
- handleActions
- handleFailure
- handleSuccess
- hasState
- hasVerbSubscriptionConnection
- initialize
- set
- setState
- setVerbSubscriptionConnection
- tryDestroyAfterUsing
- tryDestroyDirectObjectAfterUsing
- tryDestroyIndirectObjectAfterUsing
- tryToInferIndirectObject
- tryToPutThisInThatAspect
- unsetVerbSubscriptionConnection
- validate
Properties:
- accepts_direction
- accepts_number
- accepts_string
- adjectives
- article
- dictionary
- direction_preposition
- doVerb
- doVerbFromThis
- doVerbThatFromThis
- doVerbThatWithThis
- doVerbThis
- doVerbThisFromThat
- doVerbThisWithThat
- doVerbWithThis
- enqueue_collections
- extends
- game
- in_can_mean_on
- input_substitutions
- is_compass_direction
- is_direction
- is_spatial_direction
- let_verb_handle_disambiguation
- let_verb_handle_remaining_input
- name
- Name
- override_verb_failure_msg
- override_verb_success_msg
- past_tense
- player_must_be
- prettyname
- related
- requires_number
- requires_string
- state
- state_strings
- 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 |
canBeIntransitive()
Defined in: adventure/dictionary/Verb.js, line 1905
do()
Defined in: adventure/dictionary/Verb.js, line 968
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 1233
doTry()
Defined in: adventure/dictionary/Verb.js, line 1138
enqueueCollection()
Defined in: adventure/dictionary/Verb.js, line 1582
getState()
Defined in: adventure/dictionary/Verb.js, line 1923
handleActions()
Defined in: adventure/dictionary/Verb.js, line 1153
handleFailure()
Defined in: adventure/dictionary/Verb.js, line 1620
handleSuccess()
Defined in: adventure/dictionary/Verb.js, line 1718
hasState()
Defined in: adventure/dictionary/Verb.js, line 1914
hasVerbSubscriptionConnection()
Defined in: adventure/dictionary/Verb.js, line 2064
initialize()
Defined in: adventure/dictionary/Verb.js, line 1547
Todos: How does patchVerb handle initialization?
set(props) → {adventurejs.Verb}
Defined in: adventure/dictionary/Verb.js, line 1608
Parameters:
-
props
Object
A generic object containing properties to copy to the DisplayObject instance.
setState()
Defined in: adventure/dictionary/Verb.js, line 1932
setVerbSubscriptionConnection()
Defined in: adventure/dictionary/Verb.js, line 1941
computer.dov.plugIn.with_params.connections = ['socket']
socket.iov.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.dov.plugIn.with_assets = ['socket']
connections:
computer.dov.plugIn.with_params.connections = ['socket']
tryDestroyAfterUsing(object_of, asset) → {Object}
Defined in: adventure/asset/tryDestroyAfterUsing.js, line 7
Parameters:
-
object_of
String -
asset
Object
Returns:
Object
tryDestroyDirectObjectAfterUsing(asset) → {Boolean|string}
Defined in: adventure/asset/tryDestroyDirectObjectAfterUsing.js, line 7
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 7
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 1292
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 1369
Parameters:
-
direct_object
Object -
preposition
String -
indirect_object
Object
Returns:
Object
unsetVerbSubscriptionConnection()
Defined in: adventure/dictionary/Verb.js, line 2009
computer.dov.plugIn.with_params.connections = ['socket']
socket.iov.plugIn.with_params.connections = ['computer']
validate()
Defined in: adventure/dictionary/Verb.js, line 1540
Properties |
accepts_direction :String
Defined in: adventure/dictionary/Phrase.js, line 27
accepts_number :String
Defined in: adventure/dictionary/Phrase.js, line 41
accepts_string :String
Defined in: adventure/dictionary/Phrase.js, line 20
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 251
article :Boolean
Defined in: adventure/dictionary/Verb.js, line 328
Default value: false
dictionary :Object
Defined in: adventure/dictionary/Verb.js, line 144
Default value: {}
direction_preposition :Boolean
Defined in: adventure/dictionary/Verb.js, line 340
Default value: ""
doVerb :Getter
Defined in: adventure/dictionary/Verb.js, line 487
doVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 503
doVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 543
doVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 527
doVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 495
doVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 535
doVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 519
doVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 511
enqueue_collections :Array
Defined in: adventure/dictionary/Verb.js, line 406
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 165
Default value: ""
game :Object
Defined in: adventure/dictionary/Verb.js, line 137
Default value: {}
in_can_mean_on :Boolean
Defined in: adventure/dictionary/Verb.js, line 295
Default value: false
input_substitutions :Object
Defined in: adventure/dictionary/Verb.js, line 357
Default value: {}
is_compass_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 311
Default value: false
is_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 304
Default value: false
is_spatial_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 319
Default value: false
let_verb_handle_disambiguation :Boolean
Defined in: adventure/dictionary/Verb.js, line 275
Default value: false
let_verb_handle_remaining_input :Boolean
Defined in: adventure/dictionary/Verb.js, line 284
Default value: false
name :String
Defined in: adventure/dictionary/Verb.js, line 174
Default value: ""
Name :Getter
Defined in: adventure/dictionary/Verb.js, line 422
Default value: []
override_verb_failure_msg :String
Defined in: adventure/dictionary/Verb.js, line 369
Default value: undefined
override_verb_success_msg :String
Defined in: adventure/dictionary/Verb.js, line 378
Default value: undefined
past_tense :String
Defined in: adventure/dictionary/Verb.js, line 191
player_must_be :Object
Defined in: adventure/dictionary/Verb.js, line 259
Default value: {}
prettyname :String
Defined in: adventure/dictionary/Verb.js, line 182
requires_number :String
Defined in: adventure/dictionary/Phrase.js, line 48
requires_string :String
Defined in: adventure/dictionary/Phrase.js, line 34
state :String
Defined in: adventure/dictionary/Verb.js, line 198
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 218
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.
synonyms :Getter/Setter
Defined in: adventure/dictionary/Verb.js, line 551
Default value: []
tryVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 447
tryVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 479
tryVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 463
tryVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 431
tryVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 471
tryVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 455
tryVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 439
type :String
Defined in: adventure/dictionary/Verb.js, line 152
Default value: ""
unstate :String
Defined in: adventure/dictionary/Verb.js, line 208
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 617
Default value: []
verb_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 781
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 870
Default value: []
verb_noun_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 828
Default value: []
verb_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 658
Default value: []
verb_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 575
Default value: []
verb_prep_noun_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 916
Default value: []
verb_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 699
Default value: []
verb_prep_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 740
Default value: []