Customize Verbs:Process of a Verb
Once the game's parser succeeds in breaking a sentence down into nouns and a verb, it calls game.dictionary.doVerb(verb), which in turn calls verb.do(). Verbs vary in complexity from simple to very complex. They can contain various amounts of specific conditional logic to test whether and how they can be applied. They can also test at multiple points for custom code injections.
- Increment try verb count
Keeps a count of every time a verb is attempted on an asset, a number that is available for use by authors through asset._didTry(verb).
- Check verb subscription for doBeforeTry verb phase
Authors may inject custom code by setting a doBeforeTry verb phase in any asset's verb subscription. This allows an author to inject custom logic that runs before the verb's default doTry logic.
- Apply specific verb logic
Many verbs share common blocks and patterns, though each verb may also have distinct logic at any point.
- callAction tryVerbThis
Verb actions are another way for authors to inject custom code. Verb actions can be assigned to specific assets, to call custom code whenever a certain verb-related event is applied to them. Verb actions differ from verb phases in that verb actions may be called from within the doTry or doSuccess phases. Additionally, some verb actions, such as doMoveThatToThis, are not verb-specific and may be called by multiple verbs. Though these are technically identical to verb actions, we refer to these non verb-related events as verb reactions.
- Apply verb's specific sentence structure logic
It's common that each sentence structure a verb handles will have some amount of distinct logic. For example, consider the differences in handling input like "look" vs "look at reflection in mirror". One is an intransitive verb with no object that might only need to print the current room description, while the other may need to test for the existence of two assets and the relationship between them.
- callAction tryVerbThisWithThat
Verb actions are another way for authors to inject custom code. Verb actions can be assigned to specific assets, to call custom code whenever a certain verb-related event is applied to them. Verb actions differ from verb phases in that verb actions may be called from within the doTry or doSuccess phases. Additionally, some verb actions, such as doMoveThatToThis, are not verb-specific and may be called by multiple verbs. Though these are technically identical to verb actions, we refer to these non verb-related events as verb reactions.
- callAction tryVerbThatWithThis
See how this hook is onTryThatWithThis vs the previous hook onTryThisWithThat. That is because, given a direct object and an indirect object, either one may have a verb action hooked into it. Adventurejs does this to give authors more flexibility in where they may place custom code.
- Apply verb's specific sentence structure logic
It's common that each sentence structure a verb handles will have some amount of distinct logic. For example, consider the differences in handling input like "look" vs "look at reflection in mirror". One is an intransitive verb with no object that might only need to print the current room description, while the other may need to test for the existence of two assets and the relationship between them.
- Check verb for override_verb_failure_msg
This is a simple way to override a verb's failure messages. If set, it will override any message generated by a verb's doTry phase. This is a broad override that applies to all assets. Useful if you don't want to use a verb's built-in failure messages but also don't want to rewrite every one of them. However, note that it doesn't override messages generated by the parser before reaching the verb, which includes failures caused by unacceptable sentence structures, not enough or too many nouns, assets that don't meet minimum requirements, etc.
- Check verb subscription for on_first_failure
Any asset can be set to print a custom string the first time a specific verb fails to be applied to it. For example, set it so that climb stairs when applied the first time results in printing "You feel dizzy and fall back down the stairs."
- Check verb subscription for on_failure
Any asset can be set to print a custom string any time a specific verb fails to be applied to it. For example, set it so that close door when applied to a certain door results in printing "The door just won't quite shut."
- Check verb subscription for doAfterTry verb phase
Authors may inject custom code by setting a doAfterTry verb phase in any asset's verb subscription. This allows an author to inject custom logic that runs immediately after the verb's default doTry logic.
- Check verb subscription for doBeforeSuccess verb phase
Authors may inject custom code by setting a doBeforeSuccess verb phase in any asset's verb subscription. This allows an author to inject custom logic that runs before the verb's default doSuccess logic. In practical terms, doBeforeSuccess is effectively the same as doAfterTry; which one to use is up to personal preference.
- callAction doVerbThis
Verb actions are another way for authors to inject custom code. Verb actions can be assigned to specific assets, to call custom code whenever a certain verb-related event is applied to them. Verb actions differ from verb phases in that verb actions may be called from within the doTry or doSuccess phases. Additionally, some verb actions, such as doMoveThatToThis, are not verb-specific and may be called by multiple verbs. Though these are technically identical to verb actions, we refer to these non verb-related events as verb reactions.
- Apply verb's specific sentence structure logic
It's common that each sentence structure a verb handles will have some amount of distinct logic. For example, consider the differences in handling input like "look" vs "look at reflection in mirror". One is an intransitive verb with no object that might only need to print the current room description, while the other may need to test for the existence of two assets and the relationship between them.
- callAction doVerbThisWithThat
Verb actions are another way for authors to inject custom code. Verb actions can be assigned to specific assets, to call custom code whenever a certain verb-related event is applied to them. Verb actions differ from verb phases in that verb actions may be called from within the doTry or doSuccess phases. Additionally, some verb actions, such as doMoveThatToThis, are not verb-specific and may be called by multiple verbs. Though these are technically identical to verb actions, we refer to these non verb-related events as verb reactions.
- callAction doVerbThatWithThis
See how this hook is onDoThatWithThis vs the previous hook onDoThisWithThat. That is because, given a direct object and an indirect object, either one may have a verb action hooked into it. Adventurejs does this to give authors more flexibility in where they may place custom code.
- Apply verb's specific sentence structure logic
It's common that each sentence structure a verb handles will have some amount of distinct logic. For example, consider the differences in handling input like "look" vs "look at reflection in mirror". One is an intransitive verb with no object that might only need to print the current room description, while the other may need to test for the existence of two assets and the relationship between them.
- Apply state changes
For example, using verb lock on an asset may set asset.is.locked to true.
- Compose output
Many verbs will tailor their output depending on conditions such as whether an indirect object was used, the state of the assets effected, or the player's posture or position.
- Check verb for override_verb_success_msg
This is a simple way to override a verb's success messages. It can be set in an author's game file. If set, it will override the message generated by the compose output block in a verb's doSuccess phase. This is a broad override that applies to all assets. Useful if you don't want the built-in messages but don't want to rewrite every one of them.
- Increment do verb count
Keeps a count of every time a verb is applied to an asset, a number that is available for use by authors through asset._didDo(verb).
- Check verb subscription for on_first_success
Any asset can be set to print a custom string the first time a specific verb is applied to it, by setting its verb subscription's on_first_success property. For example, set it so that "climb stairs" when applied the first time results in printing "You feel dizzy when you reach the top."
- Check verb subscription for on_success
Any asset can be set to print a custom string any time a specific verb is applied to it, by setting its verb subscription's on_success property. For example, set it so that "close door" when applied to a certain door results in printing "The door creaks shut eerily."
- Check verb subscription for then_destroy
Any asset can be set to be destroyed after a specific verb is applied to it, by setting its verb subscription's then_destroy property to true. For example, consider a lockpick that breaks after a single use.
- Check verb subscription for doAfterSuccess verb phase
Authors may inject custom code by setting a doAfterSuccess verb phase in any asset's verb subscription. This allows an author to inject custom logic that runs after the verb's default doSuccess logic.