Start Scripting:Verb Phases
Verb Phases body text.
direct and indirect3 ways to use Verb Phases
1 is through the use of verb_reactions - item by item
2 is through the use of action_reactions 3 is by overriding verb methods
see settings.show_disambiguation_as_ordered_list
and settings.show_disambiguation_as_numbered_paragraph
doBeforeTry provides a hook for authors to add custom verb code to individual Assets. doBeforeTry fires before doTry, which contains most of the specific logic for determining if this Verb is allowed to act on the specified Asset. Hooking into doBeforeTry allows authors to inject custom logic on an item-by-item basis that runs before any of the standard doTry logic. For more information about Verb Phases, see Verb Phases. For information about modifying Verbs, see Modify Verbs. @memberOf adventurejs.Verb @method adventurejs.Verb#doBeforeTry
doAfterTry provides a hook for authors to add custom verb code to individual Assets. doAfterTry fires after doTry, which contains most of the specific logic for determining if this Verb is allowed to act on the specified Asset. Hooking into doAfterTry allows authors to inject custom logic that runs after the Asset has successfully passed through the standard doTry logic. This essentially lets you append custom conditional logic to doTry on an item-by-item basis without globally modifying doTry (which is also possible). If doAfterTry returns null or false, Verb.do will exit without executing the remaining methods. If Verb.do is parsing a collection of objects, returning null will continue to the next object and returning false will block all remaining objects. For more information about Verb Phases, see the Verb Phases. For information about modifying Verbs, see Modify Verbs. @memberOf adventurejs.Verb @method adventurejs.Verb#doAfterTry
doBeforeSuccess provides a hook for authors to add custom verb code to individual Assets. doBeforeSuccess fires after doTry and before doSuccess, which contains all code for applying this Verb to the specified Asset. Hooking into doBeforeSuccess allows authors to inject custom code that runs before the standard doSuccess code. This essentially lets you override doSuccess on an item-by-item basis without globally modifying doSuccess (which is also possible). If doBeforeSuccess returns null, it will prevent doSuccess from firing. For more information about Verb Phases, see the Verb Phases. For information about modifying Verbs, see Modify Verbs. @memberOf adventurejs.Verb @method adventurejs.Verb#doBeforeSuccess
doAfterSuccess provides a hook for authors to add custom verb code to individual Assets. doAfterSuccess fires after doSuccess, which means that any custom code here follows the standard doSuccess code. For more information about Verb Phases, see the Verb Phases. For information about modifying Verbs, see Modify Verbs. @memberOf adventurejs.Verb @method adventurejs.Verb#doAfterSuccess
verb_hooks is an object used
to store an authors' custom verb hooks for this asset.
Any verb may be overridden for any singular asset.
In this example,
we hook the take.doBeforeTry
,
take.doAfterTry
,
take.doBeforeSuccess
,
take.doAfterSuccess
,
and drop.doAfterSuccess
events in order
to print custom messages as the player interacts with this asset.
MyGame.createAsset({
class: "Sword",
name: "singing sword",
verb_hooks: {
take:
{
doBeforeTry: function( params )
{
MyGame.print( "The sword quivers as you reach for
it. ", "concatenate_output" );
},
doAfterTry: function( params )
{
MyGame.print( "The sword begins to vibrate as your hand
curls around its haft. ", "concatenate_output" );
},
doBeforeSuccess: function( params )
{
MyGame.print( "The sword's vibration grows into a hum. ",
"concatenate_output" );
},
doAfterSuccess: function( params )
{
MyGame.print( "The sword bursts into full on song in your hand. ",
"concatenate_output" );
},
},
drop:
{
doAfterSuccess: function( params )
{
MyGame.print( "The sword bursts into a tearful dirge as it
falls to the floor. ", "concatenate_output" );
},
},
},
});
To learn more about verb hooks... TODO
Verb phases exist in an asset's verb subscription.
They're expected to execute code and return only TRUE | FALSE | NULL | UNDEFINED
Returning TRUE or no value (aka UNDEFINED) lets the verb continue
Returning NULL ends operations for this asset. If multiple actions are queued, operations will continue.
Returning FALSE ends operations for all queued actions as well as this one.