Advanced Verb Use:Verb Properties
A verb is defined by properties of language and logic. Many of the logical properties are used to help define circumstances that the verb can't handle, acting as logic gates. Verbs also inherit methods that handle failure states and success states. Below is a list of definable properties.
-
name,past_tense,synonymsandgerundall define language for the verb. -
accepts_structuressets what sentence structures the verb can handle, such as "noun preposition noun preposition" which helps to filter out player input that can't be handled. -
subject_must_besets requirements for the subject of the verb. For example if a player is tied to a chair, they shouldn't be able to move, so we setsubject_must_be: { not_constrained: true }. -
phrasesset requirements for object phrases, which includes both nouns and prepositions: such as whether an object is reachable, using the nested propertynoun_must_be: reachable; whether or not a preposition is required; etc. -
with_paramsis used to store irregular verb parameters. It's unused for most verbs, but can be helpful, for example, with verbs that make connections, such astieandplugIn, for storing arbitrary property such as how many connections the verb can make. -
doTryis a method that handles all the logic to determine if a verb can act on a specific object. -
doSuccessis a method that handles state changes and printing the result back to the player.
There is, additionally, a lesser used set of properties that can be used to define phrasal verb patterns, which we separate out into its own doc.
Documentation for all of AdventureJS's predefined verbs is available in the Verb Reference. Verb utility functions allow you to enable / disable verbs for all assets, modify verbs, combine verbs, replace verbs entirely, or create new verbs.
If you want to do a deep dive into verb anatomy and verb process, we go into much greater detail in Advanced Verb Use: Verb Anatomy and Advanced Verb Use: Verb Process.
Example
Here is an example of a verb definition. There is some flexibility to the
structure. For example, verbs may have from one to three phrases. Some verbs
have state and unstate properties which are used to
change the state of objects the verb is applied to. Some verbs may include
lesser used phrasal noun properties.
A.Preverbs.bark = {
name: "bark",
past_tense: "barked",
synonyms: ["woof"],
gerund: "barking",
accepts_structures: [
"verb", // bark
"verb preposition noun", // bark at something
],
subject_must_be: ( not_constrained: true, ),
phrase1: {
accepts_noun: true,
noun_must_be: {
known: true,
present: true,
},
},
with_params: {},
doTry: function () {
const input = this.game.getInput();
const direct_object = input.getAsset(1);
const direct_preposition = input.getPreposition(1);
let msg = "";
// here is where we put all of our logic to determine
// whether this verb can be applied in this circumstance
if (direct_object && !direct_object.isDOV(this.name)) {
msg += `{We} can't bark at ${direct_object.article_name}. `;
this.handleFailure(msg);
return false;
}
return true;
},
doSuccess: function () {
const input = this.game.getInput();
const direct_object = input.getAsset(1);
const direct_preposition = input.getPreposition(1);
let msg = "";
// here is where we put all of our logic to handle
// state changes and output
if(direct_object) {
msg += `{We} bark at ${direct_object.article_name}. `;
} else {
msg += `{We} bark! `;
}
return this.handleSuccess(msg);
},
}