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.
- modifyVerb() 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,
twistandturnare 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:
// modifyVerb()
MyGame.modifyVerb({
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:
-
gameadventurejs.Game
A reference to the game instance.
- Index
- Methods
- Properties
Index
Methods:
- agree
- canBeIntransitive
- do
- doSuccess
- doTry
- enqueueCollection
- findQualifiedSynonym
- 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
- can_try
- default_direction
- dictionary
- direction_preposition
- doVerb
- doVerbFromThis
- doVerbThatFromThis
- doVerbThatWithThis
- doVerbThis
- doVerbThisFromThat
- doVerbThisWithThat
- doVerbWithThis
- enqueue_collections
- extends
- game
- gerund
- 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_failure_msg
- override_success_msg
- past_tense
- phrase1
- phrase2
- phrase3
- posture
- posture
- prettyname
- related
- requires_number
- requires_string
- state
- state_strings
- subject_must_be
- synonyms
- synonyms
- try_gerund
- try_to_verb
- tryVerbFromThis
- tryVerbThatFromThis
- tryVerbThatWithThis
- tryVerbThis
- tryVerbThisFromThat
- tryVerbThisWithThat
- tryVerbWithThis
- type
- unstate
- verb_gerund
- 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 3371
canBeIntransitive
canBeIntransitive()
Defined in: adventure/dictionary/Verb.js, line 3105
do
do()
Defined in: adventure/dictionary/Verb.js, line 1293
do ->
- doBeforeTry (hook for authors)
- doTry
- doAfterTry (hook for authors)
- doBeforeSuccess (hook for authors)
- doSuccess
- doAfterSuccess (hook for authors)
A Verb instance doesn't have to use all of these methods. Some specialized Verbs including 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 2123
doTry
doTry()
Defined in: adventure/dictionary/Verb.js, line 1722
enqueueCollection
enqueueCollection()
Defined in: adventure/dictionary/Verb.js, line 2743
findQualifiedSynonym
findQualifiedSynonym(value)
Defined in: adventure/dictionary/Verb.js, line 698
Parameters:
-
valueString
getState
getState()
Defined in: adventure/dictionary/Verb.js, line 3123
handleActions
handleActions()
Defined in: adventure/dictionary/Verb.js, line 1737
handleFailure
handleFailure()
Defined in: adventure/dictionary/Verb.js, line 2787
handleSuccess
handleSuccess()
Defined in: adventure/dictionary/Verb.js, line 2894
hasState
hasState()
Defined in: adventure/dictionary/Verb.js, line 3114
hasStructure
hasStructure() → {boolean}
Defined in: adventure/dictionary/Verb.js, line 3141
Returns:
boolean
hasVerbSubscriptionConnection
hasVerbSubscriptionConnection()
Defined in: adventure/dictionary/Verb.js, line 3272
initialize
initialize()
Defined in: adventure/dictionary/Verb.js, line 2714
Todos: How does modifyVerb handle initialization?
set
set(props) → {adventurejs.Verb}
Defined in: adventure/dictionary/Verb.js, line 2775
Parameters:
-
propsObject
A generic object containing properties to copy to the DisplayObject instance.
setState
setState()
Defined in: adventure/dictionary/Verb.js, line 3132
setVerbConnection
setVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 3151
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_ofString -
assetObject
Returns:
Object
tryDestroyDirectObjectAfterUsing
tryDestroyDirectObjectAfterUsing(asset) → {Boolean|string}
Defined in: adventure/asset/tryDestroyDirectObjectAfterUsing.js, line 6
Parameters:
-
assetObject
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:
-
assetObject
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 2225
Parameters:
-
optionsObject
An object of options.Properties
-
direct_objectObject -
handle_inputBoolean
If true, updates the global input object per standard specs used by most (but not all) of the verb instances that call this method. -
contextObject
The subject, usually player, could be an NPC. -
infer_first_useBoolean
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 2442
Parameters:
-
direct_objectObject -
prepositionString -
indirect_objectObject
Returns:
Object
unsetVerbConnection
unsetVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 3212
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 2707
Properties |
accepts_adverbs
accepts_adverbs :Array
Defined in: adventure/dictionary/Verb.js, line 445
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 439
Default value: []
adjectives
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 312
adjectives
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 320
allow_iov_on_iov
allow_iov_on_iov :Array
Defined in: adventure/dictionary/Verb.js, line 513
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 401
Default value: false
can_span
can_span :String
Defined in: adventure/dictionary/Verb.js, line 249
can_try
can_try :String
Defined in: adventure/dictionary/Verb.js, line 212
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 413
Default value: ""
doVerb
doVerb :Getter
Defined in: adventure/dictionary/Verb.js, line 609
doVerbFromThis
doVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 625
doVerbThatFromThis
doVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 665
doVerbThatWithThis
doVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 649
doVerbThis
doVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 617
doVerbThisFromThat
doVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 657
doVerbThisWithThat
doVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 641
doVerbWithThis
doVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 633
enqueue_collections
enqueue_collections :Array
Defined in: adventure/dictionary/Verb.js, line 500
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 206
gerund
gerund :Getter/Setter
Defined in: adventure/dictionary/Verb.js, line 673
Default value: []
in_can_mean_on
in_can_mean_on :Boolean
Defined in: adventure/dictionary/Verb.js, line 368
Default value: false
input_substitutions
input_substitutions :Object
Defined in: adventure/dictionary/Verb.js, line 451
Default value: {}
is_compass_direction
is_compass_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 384
Default value: false
is_direction
is_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 377
Default value: false
is_relative_direction
is_relative_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 392
Default value: false
let_verb_handle_disambiguation
let_verb_handle_disambiguation :Boolean
Defined in: adventure/dictionary/Verb.js, line 348
Default value: false
let_verb_handle_remaining_input
let_verb_handle_remaining_input :Boolean
Defined in: adventure/dictionary/Verb.js, line 357
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 533
Default value: []
override_failure_msg
override_failure_msg :String
Defined in: adventure/dictionary/Verb.js, line 463
Default value: undefined
override_success_msg
override_success_msg :String
Defined in: adventure/dictionary/Verb.js, line 472
Default value: undefined
past_tense
past_tense :String
Defined in: adventure/dictionary/Verb.js, line 200
phrase1
phrase1 :Object
Defined in: adventure/dictionary/Verb.js, line 421
Default value: {}
phrase2
phrase2 :Object
Defined in: adventure/dictionary/Verb.js, line 427
Default value: {}
phrase3
phrase3 :Object
Defined in: adventure/dictionary/Verb.js, line 433
Default value: {}
posture
posture :String
Defined in: adventure/dictionary/Verb.js, line 219
posture
posture :String
Defined in: adventure/dictionary/Verb.js, line 227
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 260
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 280
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 328
Default value: {}
synonyms
synonyms :String
Defined in: adventure/dictionary/Verb.js, line 194
synonyms
synonyms :Getter/Setter
Defined in: adventure/dictionary/Verb.js, line 715
Default value: []
try_gerund
try_gerund :Array
Defined in: adventure/dictionary/Verb.js, line 873
Default value: []
try_to_verb
try_to_verb :Array
Defined in: adventure/dictionary/Verb.js, line 916
Default value: []
tryVerbFromThis
tryVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 569
tryVerbThatFromThis
tryVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 601
tryVerbThatWithThis
tryVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 585
tryVerbThis
tryVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 553
tryVerbThisFromThat
tryVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 593
tryVerbThisWithThat
tryVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 577
tryVerbWithThis
tryVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 561
type
type :String
Defined in: adventure/dictionary/Verb.js, line 151
Default value: ""
unstate
unstate :String
Defined in: adventure/dictionary/Verb.js, line 270
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_gerund
verb_gerund :Array
Defined in: adventure/dictionary/Verb.js, line 742
Default value: []
verb_noun_prep
verb_noun_prep :Array
Defined in: adventure/dictionary/Verb.js, line 829
Default value: []
verb_noun_prep_noun
verb_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1092
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 1189
Default value: []
verb_noun_prep_prep_noun
verb_noun_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1143
Default value: []
verb_prep_noun
verb_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 960
Default value: []
verb_prep_noun_prep_noun
verb_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 784
Default value: []
verb_prep_noun_prep_noun_prep_noun
verb_prep_noun_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1238
Default value: []
verb_prep_prep_noun
verb_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1004
Default value: []
verb_prep_prep_prep_noun
verb_prep_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1048
Default value: []