Verb:write
Instance of: adventurejs.Verb
Defined in: adventure/dictionary/verbs/write.js, line 6
More info: VerbSubscriptions VerbAnatomy VerbProcess ModifyVerbs WriteVerbs
Description
> write on blackboard with chalk
You scribble a hasty formula on the blackboard with the chalk.
Hmm, no, that doesn't look right.
Write on a Tangible
Asset.
Requires that the writing Asset has
asset.iov.write.enabled
set to true and that the target has
asset.dov.write.enabled
set to true.
Write saves a record
of things written on an Asset to its
written_strings
property, which can be appended to the Asset's description.
Demo
// WritingDemo.js
// ----------
/*global adventurejs WritingDemo*/
var WritingDemo = new adventurejs.Game("WritingDemo", "WritingDemoDisplay").set(
{
// title, version, and author are shown in the title bar
title: "Writing Demo",
version: "0.0.1",
author: "Ivan Cockrum",
description: "This is my great game! Thanks for playing!",
}
);
// Let's set some Game settings
WritingDemo.settings.set({
// apply_color_classes_to_written_strings: true,
// if any of these are true, adventurejs will log
// messages to the browser's console
// See the full list of available settings in
// /doc/adventure_Settings.js.html
log_keywords: {
verbaction: true,
verbreaction: true,
verbphase: true,
game: true,
parser: true,
verb: true,
},
// if any of these are true, adventurejs will print
// debug messages to the game display
debug_keywords: {
general: true,
verbaction: true,
verbreaction: true,
verbphase: true,
},
// if this is true, the game won't infer objects
// until player has already used them
// good for preventing spoilers but can be annoying
objects_must_be_used_before_inferring: false,
// if this is true, lists of exits will
// show the names of rooms they lead to
show_room_names_in_exit_descriptions: true,
// if this is true, lists of exits will
// only include room names known to player
show_room_names_in_exit_descriptions_only_when_room_is_known: false,
// if this is true, lists of exits will only
// show room names for exits player has used
show_room_names_in_exit_descriptions_only_after_exit_has_been_used: false,
// if this is true, verbose room descriptions will be
// shown on first visit regardless of verbosity settings
print_verbose_room_descriptions_on_first_visit: true,
// set this to set a default response to
// player input that is not understood
if_parser_has_no_response_print_this: "I have no response to your input. ",
// set this to provide a default
// response to blank input
if_input_is_empty_print_this: "I didn't see any input. ",
// alternately, game can be set to print
// the current room description with
// if_input_is_empty_print_room_description: true
// when the parser infers an action, it may print
// the inference, such as "take pot (from stove)"
// for this game we want to turn these off
print_inferred: false,
});
WritingDemo.createAsset({
class: "Room",
name: "Writing Demo Foyer",
// setting definite_article to "the" sets it so the room
// name appears as "the Writing Demo Foyer" in lists
definite_article: "the",
descriptions: {
look: `Welcome to the Writing Demo, where you can try interacting with assets of several related classes including
WritingImplement
(Pen,
Pencil,
Chalk,
Marker),
WritingSurface
(Paper,
Blackboard,
Whiteboard),
PenCap,
Typewriter, and
Eraser. Try
writing,
typing, and
erasing things.
Visit the other rooms in this demo to find some
demonstrations. `,
brief: `Try verbs.
Read,
write,
type,
erase. `,
},
exits: {
north: "Classroom",
south: "Library",
east: "Office",
west: "Playroom",
},
}); // Writing Demo Foyer
WritingDemo.createAsset({
class: "Player",
name: "Will",
place: { in: "Writing Demo Foyer" },
is: { active: true },
pronouns: "second",
});
// createClass()
// We're going to create several pieces of paper for this game.
// AdventureJS has a Paper class, but we want to add some
// specific properties to every instance of Paper. First, we
// want to specify several subclasses of WritingImplements that
// can write on them - Pen, Pencil, Crayon - but not Chalk or
// Marker. Then, we want to specify a particular Eraser that
// can erase them - the rubber eraser but not the Whiteboard
// eraser or Blackboard eraser.
//
// This is a minimal class definition. It extends the
// Paper class by customizing its write and erase verb
// subscriptions.
//
// Creating custom classes is an advanced move, so if you decide
// to create some, be sure to RTFM and test them extensively.
// See https://adventurejs.com/doc/Advanced_CustomClasses.html
// for more info.
WritingDemo.createClass(
class CustomPaper extends adventurejs.Paper {
constructor(name, game_name) {
super(name, game_name);
this.class = "CustomPaper";
// Limit what classes can write on this class.
this.setIOV({
write: { with_classes: ["Crayon", "Pen", "Pencil"] },
});
// Limit what assets can erase this class.
this.setDOV({
erase: { with_assets: ["rubber eraser"] },
});
// We want to set a custom message when a player tries
// and fails to type on this class. Though it seems
// that "type on paper" would have paper be a direct
// object, type is tricky to parse because technically,
// the information being typed is the direct object,
// even if no information is specified. So, for type,
// the paper and the typewriter are both indirect
// objects.
this.setIOV({
write: {
on_success: function () {
WritingDemo.scorecard.completeEvent("write on paper");
},
},
type: {
// This is a valid way to return a message, but...
// on_failure: `{We} might try putting it in a typewriter. `,
// ...we're going to be nitpicky about how we refer
// to the typewriter. If it's present we'll say
// "the typewriter" and if it's not we'll say
// "a typewriter". We'll use some embedded Javascript
// to test the typewriter's presence.
on_failure: () => {
return `{We} might try putting it in ${
WritingDemo.$("typewriter").$is("present") ? "the" : "a"
} typewriter. `;
},
},
});
}
}
);
// now we can create an instance of our new CustomPaper class
WritingDemo.createAsset({
class: "CustomPaper",
name: "pink paper",
indefinite_article: "a sheet of",
synonyms: ["sheet", "sheet of pink paper"],
description: "It's a sheet of pink paper. ",
place: { in: "Writing Demo Foyer" },
});
// Office.js
// ----------
/*global adventurejs A WritingDemo*/
WritingDemo.createAsset({
class: "Room",
name: "Office",
definite_article: "the",
descriptions: {
look: `This office is dominated by an oak mission style desk
with an old fashioned office chair. One wall is covered by a
whiteboard, with a narrow ledge for accessories. Try writing
on things with other things. See the example code
in Office.js for particulars. `,
brief: "Time to get to work. ",
},
exits: { west: "Writing Demo Foyer" },
}); // Office
// createClass()
// Later in this file, we'll create several whiteboard markers.
// We already have a class, Marker, but we want a specific
// WhiteboardMarker class that will be the only class of
// Assets that are allowed to write on a Whiteboard.
//
// This is the bare minimum needed for a class definition.
// The only thing that sets it apart from Marker is the class
// name, but that's how instances of the class will be
// identified by verb methods trying to determine whether
// the classes can be used together.
//
// Creating custom classes is an advanced move, so if you decide
// to create some, be sure to RTFM and test them extensively.
// See https://adventurejs.com/doc/Advanced_CustomClasses.html
// for more info.
WritingDemo.createClass(
class WhiteboardMarker extends adventurejs.Marker {
constructor(name, game_name) {
super(name, game_name);
this.class = "WhiteboardMarker";
}
}
);
WritingDemo.createAsset({
class: "Whiteboard",
name: "whiteboard",
place: { in: "Office" },
description: `It's a classic office whiteboard. `,
// Because the whiteboard is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { listed: false },
dov: {
// Though player can use an eraser to erase the whiteboard,
// setting whiteboard.dov.erase.with_nothing = true allows
// the player to erase the whiteboard without another asset,
// which we'll understand to mean that they're using their hand.
// (In fact this is the default setting for class Whiteboard,
// but we're redefining it here just to make this point.)
erase: {
with_nothing: true,
on_success: function () {
WritingDemo.scorecard.completeEvent("erase whiteboard");
},
},
},
iov: {
// Remember where we set up our custom WhiteboardMarker class?
// setting whiteboard.dov.write.with_classes = ["WhiteboardMarker"]
// establishes that only WhiteboardMarkers can write on Whiteboard.
write: {
with_classes: ["WhiteboardMarker"],
on_success: function () {
WritingDemo.scorecard.completeEvent("write on whiteboard");
},
},
},
// Should a player erase the whiteboard without an eraser,
// the verb action doEraseThis() will be called and we can
// treat it as if player is using their hand as an eraser.
doEraseThis: function () {
WritingDemo.appendTurn(`It leaves a smudge of ink on {our} hand. `);
},
}); //
// We don't have any special class for this whiteboard
// ledge so we'll just use the generic Thing class,
// and set whatever properties we might need.
WritingDemo.createAsset({
class: "Thing",
name: "whiteboard ledge",
description: `A narrow ledge that runs the length of the whiteboard, on which to store whiteboard accessories. `,
place: { in: "Office" },
// ensure that player can take things from and put things on the ledge
iov: { take: true, put: true },
// Because the ledge is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { listed: false },
// Thing has no aspects by default, so we'll do the bare
// minimum to define an "on" aspect. Now we can put things
// on it.
aspects: { on: true },
}); //
WritingDemo.createAsset({
class: "Eraser",
name: "microfiber eraser",
place: { on: "whiteboard ledge" },
descriptions: { look: "It's a microfiber eraser. " },
// Verb subscriptions
// By setting iov.erase.with_classes to ["Whiteboard"]
// we're customizing this asset's erase verb subscription
// to establish that the whiteboard is the only
// thing this eraser can erase.
//
// This is similar to what we did with the WhiteboardMarker
// class, but we didn't bother to create a new class for
// WhiteboardErasers because there's only one of them,
// so we're just adjusting its individual properties.
iov: { erase: { with_classes: ["Whiteboard"] } },
// Verb action hooks - doEraseThatWithThis()
// Verb action hooks allow authors
// to call custom code after specific actions.
//
// Verb action hooks can be formatted in different
// ways depending on the level of specificity needed.
//
// In this case, since the whiteboard is the only thing
// the eraser can erase, we know that the "That" in
// doEraseThatWithThis must be the whiteboard, and we can
// refer to it unambiguously in this verb action hook.
doEraseThatWithThis: function () {
WritingDemo.appendTurn(
`The eraser squeaks as it's dragged across the board. `
);
},
}); //
WritingDemo.createAsset({
class: "WhiteboardMarker",
name: "red marker",
adjectives: ["red", "dry erase", "red dry erase"],
place: { on: "whiteboard ledge" },
descriptions: { look: "It's a red dry erase marker. " },
appearance: { color: "red" },
}); // RedMarker
WritingDemo.createAsset({
class: "WhiteboardMarker",
name: "orange marker",
indefinite_article: "an",
adjectives: ["orange", "dry erase", "orange dry erase"],
place: { on: "whiteboard ledge" },
descriptions: { look: "It's a orange dry erase marker. " },
appearance: { color: "orange" },
}); // OrangeMarker
WritingDemo.createAsset({
class: "WhiteboardMarker",
name: "cyan marker",
adjectives: ["cyan", "dry erase", "cyan dry erase"],
place: { on: "whiteboard ledge" },
descriptions: { look: "It's a cyan dry erase marker. " },
appearance: { color: "cyan" },
}); // CyanMarker
WritingDemo.createAsset({
class: "Desk",
name: "desk",
place: { in: "Office" },
// describeDeskDrawers() is an example of a custom function.
// See the function description below for more information.
// Note how we've set description to be a function rather than
// a string, as we've done elsewhere. That is because we're
// using a Javascript ${template literal}, which is always
// evaluated immediately, and so if we set this as a string,
// it would be evaluated at runtime, before the game has built,
// and throw an error. By making it a function, it won't be
// evaluated until we call it.
description: () =>
`It's an oak mission style desk, with an old fashioned office
chair. It has three drawers stacked vertically.
${describeDeskDrawers()}`,
synonyms: [""],
adjectives: ["mission style", "mission", "style", "oak"],
// Just for fun, let's say the player can go under the desk.
aspects: {
under: {
list_contents_in_room: false,
list_contents_in_examine: true,
nest: {
posture: "kneel",
can: { enter: true, exit: true, kneel: true, stand: false },
},
},
},
// Because the desk is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { listed: false },
});
WritingDemo.createAsset({
class: "Drawer",
name: "top drawer",
synonyms: [
"top desk drawer",
"top drawer lock",
"top drawer lock plate",
"lock",
"lock plate",
],
adjectives: ["brass"],
// Here we're using an AdventureJS custom template
// to print whether the drawer is open or closed.
// Custom templates are like Javascript template literals,
// but a little different.
description: `The top drawer has a small brass lock plate. The drawer is { top drawer [is] open [or] closed }. `,
adjectives: "desk",
place: { attached: "desk" },
// We're setting this drawer closed and locked.
// We set listed to false so it doesn't
// get listed like a piece of inventory.
is: {
closed: true,
locked: true,
listed: false,
},
// Setting dov.unlock.with_assets["tiny brass key"]
// means that only the tiny brass key can unlock this.
dov: { unlock: { with_assets: ["tiny brass key"] } },
});
WritingDemo.createAsset({
class: "Drawer",
name: "middle drawer",
synonyms: "middle desk drawer",
description: "The middle drawer is { middle drawer [is] open [or] closed }. ",
adjectives: "desk",
place: { attached: "desk" },
is: {
closed: true,
listed: false,
},
});
WritingDemo.createAsset({
class: "Drawer",
name: "bottom drawer",
synonyms: "bottom desk drawer",
description: "The bottom drawer is { bottom drawer [is] open [or] closed }. ",
adjectives: "desk",
place: { attached: "desk" },
is: {
closed: true,
listed: false,
},
});
// Collections
// In our current example, the desk has three drawers. Though
// the parser understands plurals, if a player asked for
// "desk drawers", the parser's default behavior would be
// to prompt for disambiguation: "which drawer did you mean?"
//
// From a player's perspective, that's just tedious, because
// it's perfectly reasonable to expect "examine desk drawers"
// to return a description that includes all three. That's what
// Collections are for. Collections describe a group of assets,
// so that players can refer to multiple assets with one term.
//
// In this case, "desk drawers" is a Collection that represents
// all three desk drawers.
WritingDemo.createAsset({
class: "Collection",
name: "desk drawers",
place: { attached: "desk" },
collection: "top drawer, middle drawer, bottom drawer",
synonyms: ["drawers", "three drawers"],
is: {
listed: false,
},
// describeDeskDrawers() is an example of a custom function.
// See the function description below for more information.
// Note how we've set description to be a function rather than
// a string, as we've done elsewhere. That is because we're
// using a Javascript ${template literal}, which is always
// evaluated immediately, and so if we set this as a string,
// it would be evaluated at runtime, before the game has built,
// and throw an error. By making it a function, it won't be
// evaluated until we call it.
description: () =>
`The desk has three drawers stacked vertically: top, middle and bottom. ${describeDeskDrawers()}`,
});
// describeDeskDrawers()
// Here, we've made a custom function that describes the state
// of all three desk drawers. The reason we've done this
// is so that we can show it in two places without repeating
// code. We use this in the desk's description, and also in
// the desk drawers collection. This function exists in the
// global scope, aka the browser window, which means that
// you can call it from anywhere. (Technically, this is kind
// of sloppy, and you probably shouldn't do it in other
// environments, but it won't hurt anything in AdventureJS.)
// @returns string
function describeDeskDrawers() {
const open = [];
const closed = [];
let msg = "The top drawer has a small brass lockplate. ";
// get a list of all the open drawers
// and a list of all the closed drawers
WritingDemo.$("top drawer").is.closed ? closed.push("top") : open.push("top");
WritingDemo.$("middle drawer").is.closed
? closed.push("middle")
: open.push("middle");
WritingDemo.$("bottom drawer").is.closed
? closed.push("bottom")
: open.push("bottom");
// print a slightly different description based
// on however many drawers are open or closed
switch (open.length) {
case 0:
msg += `All three drawers are closed. `;
break;
case 1:
msg += `The ${closed[0]} and ${closed[1]} drawers are closed. The ${open[0]} drawer is open. `;
break;
case 2:
msg += `The ${open[0]} and ${open[1]} drawers are open. The ${closed[0]} drawer is closed. `;
break;
case 3:
msg += `All three drawers are open. `;
break;
}
return msg;
}
WritingDemo.createAsset({
class: "Chair",
name: "office chair",
indefinite_article: "an",
place: { in: "Office" },
// It's a swivel chair, so we're going to allow
// the verb turn to act on it.
dov: { turn: true },
description: `It's an old fashioned wooden office chair that rolls on swiveling castors. `,
// Because the chair is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { listed: false },
// Use as many adjectives and synonyms as you like.
// Adding more words makes it easier for you and your
// player. It reduces players' chances of getting stuck
// playing guess-the-word, and increases your chances
// of correctly parsing players' input.
synonyms: ["castor", "castors"],
adjectives: ["old", "fashioned", "old fashioned", "heavy", "wooden"],
// This is an example of a verb reaction hook. Any time
// Will (the player character of this game) gets out of
// the chair, this string will be prepended to the
// game's default output. It's also possible to
// appendTurn or overrideTurn.
doUnnestThatFromThis: {
Will: function () {
WritingDemo.prependTurn(
`The office chair creaks as {we} climb out of it. `
);
},
},
aspects: {
on: {
// Because we're not listing the chair, things placed on it
// won't be listed either. We're explicitly setting it so
// that they will be.
list_contents_in_room: true,
// By default, when the player is nested in one asset,
// they can't reach things in/on other assets.
// Setting aspects.on.nest.can.reach["student desk"] enables
// the player to reach the desk and items in/on it,
// such as the drawers and typewriter, while sitting
// in the office chair.
nest: { can: { reach: ["desk"] } },
},
},
});
WritingDemo.createAsset({
class: "Key",
name: "tiny brass key",
image: "brasskey",
description: "It's a tiny key, made of brass. ",
adjectives: ["tiny", "brass"],
place: { on: "desk" },
});
WritingDemo.createAsset({
class: "Pencil",
name: "mechanical pencil",
adjectives: "brass",
synonyms: ["design", "designs"],
place: { on: "desk" },
description:
"It's a mechanical pencil made out of pressed brass, with intricate designs stamped into it. ",
}); // BrassPencil
WritingDemo.createAsset({
class: "Eraser",
name: "rubber eraser",
place: { on: "desk" },
description: `It's an ordinary rubber eraser. `,
iov: {
erase: {
on_success: function () {
WritingDemo.scorecard.completeEvent("erase paper");
},
},
},
}); // BrassPencil
WritingDemo.createAsset({
class: "Pen",
name: "indigo pen",
indefinite_article: "an",
adjectives: "indigo",
place: { in: "top drawer" },
descriptions: { look: "It's a pen with indigo ink. " },
appearance: { color: "indigo" },
}); // IndigoPen
WritingDemo.createAsset({
class: "Pen",
name: "yellow pen",
adjectives: "yellow",
place: { in: "top drawer" },
descriptions: { look: "It's a pen with yellow ink. " },
appearance: { color: "yellow" },
}); // YellowPen
WritingDemo.createAsset({
class: "Pen",
name: "green pen",
adjectives: "green",
place: { in: "top drawer" },
descriptions: { look: "It's a pen with green ink. " },
appearance: { color: "green" },
}); //GreenPen
WritingDemo.createAsset({
class: "PenCap",
name: "pen cap",
place: { attached: "green pen" },
descriptions: { look: "It's a cap for a pen. " },
}); //
WritingDemo.createAsset({
class: "CustomPaper",
name: "white paper",
indefinite_article: "a sheet of",
synonyms: ["sheet", "sheet of white paper"],
adjectives: [""],
description: "It's a sheet of white paper. ",
place: { on: "desk" },
dov: { erase: { with_assets: ["rubber eraser"] } },
});
// Playroom.js
// ----------
/*global adventurejs A WritingDemo*/
WritingDemo.createAsset({
class: "Room",
name: "Playroom",
definite_article: "the",
descriptions: {
look: `Generations of children have lounged upon floor cushions scattered around a low activity table.
See the example code in Playroom.js for particulars. `,
brief: "Table. Cushions. Please take your seat. ",
},
exits: { east: "Writing Demo Foyer" },
}); // Playroom
WritingDemo.createAsset({
class: "Table",
name: "activity table",
place: { in: "Playroom" },
description: `It's a low table, perfect for arts and crafting. `,
adjectives: [""],
// The activity table is mentioned in the room description,
// so we don't need it listed in the room, but we do want
// the things on it to be listed in the room.
is: { listed: false },
// By default, Table class has an under aspect which is not
// revealed until player examines table, but in this case,
// we want player to see what's under the table as soon
// as they enter the room.
aspects: {
under: { know_contents_with_parent: true, list_contents_in_room: true },
},
});
WritingDemo.createAsset({
class: "Thing",
name: "cushions",
synonyms: ["cushion"],
adjectives: ["floor"],
place: { in: "Playroom" },
description: `A gang of comfortable floor cushions. `,
is: { listed: false },
// Because we're building on the basic Thing class, we have
// to define some basic setup stuff that might otherwise have
// been preset if we'd used a more specialized class.
// (The Furniture class would been suitable for these cushions.)
// Here, we need to set up an on aspect with a nest for the
// player to enter, and specify that the activity table is
// reachable while sitting in it.
aspects: {
on: {
nest: {
posture: "sit",
can: { enter: true, exit: true, sit: true, reach: ["activity table"] },
},
},
},
// Continuing with the basic setup...
// If player says "get up", which gets parsed as "stand up",
// while sitting on the cushions, we want to ensure they
// get off the cushions, as opposed to trying to stand up
// in place on the cushions, which is the default behavior
// for stand.
quirks: { stand_means_get_off: true },
// We want to print a custom message when the player sits here.
doNestThatToThis: {
Will: () => {
WritingDemo.scorecard.completeEvent("sit on cushions");
WritingDemo.overrideTurn(
`{We} settle down cross legged among the floor cushions, {our} knees pressed against the low activity table. `
);
},
},
// We want to print a custom message when the player leaves this.
doUnnestThatFromThis: {
Will: () => {
WritingDemo.overrideTurn(
`{We} climb up off the cushions, bumping the table along the way. `
);
},
},
}); // Cushions
WritingDemo.createAsset({
class: "Pencil",
name: "blue pencil",
adjectives: ["blue", "colored"],
place: { on: "activity table" },
description: "It's a blue colored pencil. ",
appearance: { color: "blue" },
}); // BluePencil
WritingDemo.createAsset({
class: "Pencil",
name: "pink pencil",
adjectives: ["pink", "colored"],
place: { on: "activity table" },
description: `It's an pink colored pencil. `,
appearance: { color: "pink" },
}); // PinkPencil
WritingDemo.createAsset({
class: "Pencil",
name: "teal pencil",
adjectives: ["teal", "colored"],
place: { on: "activity table" },
description: `It's a teal colored pencil. `,
appearance: { color: "teal" },
}); // TealPencil
WritingDemo.createAsset({
class: "CustomPaper",
name: "drawing paper",
indefinite_article: "a sheet of",
synonyms: ["sheet", "sheet of drawing paper"],
adjectives: [""],
description: "It's a sheet of drawing paper. ",
place: { on: "activity table" },
// It isn't necessary to include this next line because it is
// baked into the Paper class, but it's worth seeing how we
// determine which WritingImplements may write on which
// WritingSurfaces. Here, we're saying that Paper is
// subscribed to the verb write with these classes. If
// player tries to write on Paper with anything else, they'll
// get an error message.
// dov: { write: { with_classes: ["Crayon", "Pen", "Pencil"] } },
dov: { erase: { with_assets: ["rubber eraser"] } },
});
WritingDemo.createAsset({
class: "Crayon",
name: "purple crayon",
adjectives: [""],
place: { under: "activity table" },
description: `It's a purple crayon. `,
// Assigning a color to a WritingImplement is optional.
// If provided, the text that is written will be printed
// back with a CSS class with the name of that color, and
// a CSS class of the particular WritingImplement subclass.
// You can use this to make that text print in that color,
// or in a different font, etc.
//
// For example, strings written with this purple crayon
// will be printed like this and appear in purple:
// foo
//
// adventurejs.css has a few standard color classes defined.
// You're welcome to customize such classes as you like.
appearance: { color: "purple" },
}); //
// Classroom.js
// ----------
/*global adventurejs A WritingDemo*/
WritingDemo.createAsset({
class: "Room",
name: "Classroom",
definite_article: "the",
descriptions: {
look: `This classroom features an antique student desk with
an attached bench, facing a large blackboard
with a narrow ledge for accessories. Try writing
on things and erasing things. See the example code in
Classroom.js for particulars. `,
brief: "Blackboard. Desk. Bench. Please take your seat. ",
},
exits: { south: "Writing Demo Foyer" },
}); // Classroom
WritingDemo.createAsset({
class: "Blackboard",
name: "blackboard",
place: { in: "Classroom" },
description: `It's a classic schoolroom blackboard. `,
// Because the blackboard is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { listed: false },
dov: {
// Though player can use an eraser to erase the blackboard,
// setting dov.erase.with_nothing = true allows the player
// to erase the blackboard without another asset.
// (This is the default setting for class Blackboard.
// We're redefining it here just to make the point.)
erase: {
with_nothing: true,
on_success: function () {
WritingDemo.scorecard.completeEvent("erase blackboard");
},
},
},
iov: {
// setting iov.write.with_classes = ["Chalk"]
// establishes that assets of class Chalk are the
// only assets allowed to write on Blackboard.
// (This is the default setting for class Blackboard.
// We're redefining it here just to make the point.)
//
// The reason why write is defined under iov rather
// than dov is because when writing, the thing being
// written is always the direct object, while both
// the writing implement and the writing surface are
// indirect objects.
write: {
with_classes: ["Chalk"],
on_success: function () {
WritingDemo.scorecard.completeEvent("write on blackboard");
},
},
},
// Should a player erase the blackboard without an eraser,
// the verb action doEraseThis() will be called and we can
// treat it as if player is using their hand as an eraser.
doEraseThis: function () {
WritingDemo.appendTurn(
`It leaves a powdering of chalk dust on {our} hand. `
);
},
}); //
// We don't have any special class for this blackboard
// ledge so we'll just use the generic Thing class,
// and set whatever properties we might need.
WritingDemo.createAsset({
class: "Thing",
name: "blackboard ledge",
description: `A narrow ledge that runs the length of the blackboard, on which to store blackboard accessories. `,
place: { in: "Classroom" },
// ensure that player can take things from and put things on the ledge
iov: { take: true, put: true },
// Because the ledge is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { listed: false },
// Thing has no aspects by default, so we'll do the bare
// minimum to define an "on" aspect. Now we can put things
// on it. Though the ledge's listed is false,
// we can still have its contents listed in the room by
// setting the on aspect's list_contents_in_room to true.
aspects: { on: { list_contents_in_room: true } },
}); //
WritingDemo.createAsset({
class: "Eraser",
name: "felt eraser",
place: { on: "blackboard ledge" },
descriptions: { look: "It's a felt eraser. " },
// Verb subscriptions
// By setting iov.erase.with_classes to ["Blackboard"]
// we're customizing this asset's erase verb subscription
// to establish that the blackboard is the only
// thing this eraser can erase.
iov: { erase: { with_classes: ["Blackboard"] } },
// Verb action hooks - doEraseThatWithThis()
// Verb action hooks allow authors
// to call custom code after specific actions.
//
// Verb action hooks can be formatted in different
// ways depending on the level of specificity needed.
//
// In this case, since the whiteboard is the only thing
// the eraser can erase, we know that the "That" in
// doEraseThatWithThis must be the whiteboard, and we can
// refer to it unambiguously in this verb action hook.
doEraseThatWithThis: {
blackboard: function () {
WritingDemo.appendTurn(`A small cloud of chalk dust puffs out. `);
},
},
}); //
WritingDemo.createAsset({
class: "Chalk",
name: "stick of white chalk",
synonyms: "white chalk",
adjectives: "white",
place: { on: "blackboard ledge" },
descriptions: { look: "It's a stick of white chalk. " },
appearance: { color: "white" },
}); //
WritingDemo.createAsset({
class: "Chalk",
name: "stick of pink chalk",
synonyms: "pink chalk",
adjectives: "pink",
place: { on: "blackboard ledge" },
descriptions: { look: "It's a stick of pink chalk. " },
// Setting appearance.color is optional, but when it's set
// for WritingImplements, anything written with that tool
// will be printed to the game display with that color as
// a CSS class name. For example:
// whatever player wrote
appearance: { color: "pink" },
}); //
WritingDemo.createAsset({
class: "Chalk",
name: "stick of blue chalk",
synonyms: "blue chalk",
adjectives: "blue",
place: { on: "blackboard ledge" },
descriptions: { look: "It's a stick of blue chalk. " },
appearance: { color: "blue" },
}); //
WritingDemo.createAsset({
class: "Paper",
name: "blue paper",
synonyms: ["sheet", "sheet of blue paper"],
indefinite_article: "a sheet of",
adjectives: [""],
description: "It's a sheet of blue paper. ",
place: { in: "student desk" },
dov: { erase: { with_assets: ["rubber eraser"] } },
});
WritingDemo.createAsset({
class: "Desk",
name: "student desk",
place: { in: "Classroom" },
description: () =>
`It's an old-fashioned lift top school desk with an
attached bench. The desk top is {student desk [is] open [or] closed}. `,
synonyms: [""],
adjectives: [""],
dov: { open: true, close: true },
// Because the desk is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { closed: true, listed: false },
// If the desk's listed were true, the things sitting
// on it would be automatically listed. But since we've made
// the desk unlisted, we need to explicitly tell the game
// to list the things on the desk.
aspects: {
on: { list_contents_in_room: true },
in: { list_contents_in_room: true },
attached: {
// We've included the bench in the desk's description, so
// we don't want it listed as an inventory item when
// the desk is examined.
list_contents_in_examine: false,
// However, we do want the bench known/seen with the desk.
// The Desk class sets know_contents_with_parent and
// see_contents_with_parent to false, because the class
// definition assumes that anything attached to the desk
// is a drawer or something similar, where you might not
// want the player knowing about their contents until they
// open the drawer. We're going to override these properties
// to ensure that the player knows/sees the bench.
know_contents_with_parent: true,
see_contents_with_parent: true,
},
},
});
WritingDemo.createAsset({
class: "Chair",
name: "bench",
place: { attached: "student desk" },
synonyms: [""],
adjectives: ["uncomfortable", "wooden"],
description: `It's an uncomfortable looking wooden bench. `,
// Because the chair is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: {
listed: false,
// Because the bench is attached to the desk, it needs the
// is.deep_nest flag to allow player to nest to it.
// Technically it wasn't necessary to attach the bench to
// the desk - we could have just described it as being
// attached without actually attaching it. In this case it's
// just a matter of organizational preference.
deep_nest: true,
},
aspects: {
on: {
// Because we're not listing the chair, things placed on it
// won't be listed either. We're explicitly setting it so
// that they will be.
list_contents_in_room: true,
// By default, when the player is nested in one asset,
// they can't reach things in/on other assets.
// Setting aspects.on.nest.can.reach["student desk"] enables
// the player to reach the desk and items in/on it,
// such as the drawers and typewriter, while sitting
// in the office chair.
nest: { can: { reach: ["student desk"] } },
},
},
// doNestThatToThis()
// This is an example of a verb reaction hook. Any time
// Will (the player character of this game) gets into or
// out of the bench, the provided string will override the
// game's default output. It's also possible to
// appendTurn or prependTurn.
doNestThatToThis: {
Will: function () {
WritingDemo.overrideTurn(`{We} fold {ourself} into the small bench. `);
},
},
doUnnestThatFromThis: {
Will: function () {
WritingDemo.overrideTurn(`{We} unfold {ourself} from the small bench. `);
},
},
});
// Library.js
// ----------
/*global adventurejs A WritingDemo*/
WritingDemo.createAsset({
class: "Room",
name: "Library",
definite_article: "the",
descriptions: {
look: `Cramped shelves full of dusty books, but they're unimportant right now. A modest rolltop desk is permanently open to display an antique typewriter. Try typing. See the example code in Library.js for particulars. `,
brief: "Shelves. Books. Desk. Type! ",
},
exits: { north: "Writing Demo Foyer" },
}); // Library
WritingDemo.createAsset({
class: "Desk",
name: "rolltop desk",
adjectives: ["modest"],
place: { in: "Library" },
description: `It's a modest rolltop desk, locked in the open position. `,
// Because the desk is mentioned in the room description,
// we don't need it listed as a piece of inventory in the room.
// We can prevent it from being listed by setting
// is.listed to false.
is: { listed: false },
}); // RolltopDesk
WritingDemo.createAsset({
class: "Scenery",
name: "cramped shelves",
place: { in: "Library" },
description: `The cramped shelves are just a scenery object. You know. For verisimilitude. `,
// The shelves, being a scenery asset, aren't
// subscribed to verb climb and can't be climbed,
// but if a player should try to climb them, we
// want to offer a snappy response.
// We have a variety of verb hooks to work with.
// In this case, tryClimb() is the simplest option.
tryClimb: () => {
WritingDemo.print(`In Soviet Russia, shelves climb you! `);
// return false ends the turn without further processing
return false;
},
}); // cramped shelves
WritingDemo.createAsset({
class: "Scenery",
name: "dusty books",
place: { in: "Library" },
description: `The dusty books are just another lousy scenery object. `,
// The books, like the shelves, are a scenery object
// that can't be interacted with, but we want to
// offer snappy responses to a few likely player actions.
tryRead: () => {
WritingDemo.print(`In Soviet Russia, books read you! `);
// return false ends the turn without further processing
return false;
},
tryTake: () => {
WritingDemo.print(`In Soviet Russia, books take you! `);
// return false ends the turn without further processing
return false;
},
}); // dusty books
WritingDemo.createAsset({
class: "CustomPaper",
name: "onionskin paper",
indefinite_article: "a sheet of",
synonyms: ["sheet", "sheet of onionskin paper"],
description: "It's a sheet of onionskin paper. ",
place: { on: "rolltop desk" },
});
WritingDemo.createAsset({
class: "Typewriter",
name: "typewriter",
adjectives: ["spindly", "old", "mechanical"],
place: { on: "rolltop desk" },
description: `It's a spindly old mechanical typewriter. `,
// By default, instances of Typewriter can be carried
// as inventory but we don't want this one to be moved
// so we're going to unset these verb subscriptions.
dov: {
take: false,
put: false,
get: false,
give: false,
move: false,
},
// Here, we want to check if there is a piece of paper
// in the typewriter when player types on it.
// There are several different ways to hook into verbs,
// ranging from broad to very granular, and taking into
// account whether the asset was the direct or indirect
// object of the verb. That gets a little tricky with
// the verb type, because player may input
// "type on typewriter", "type on paper",
// "type 'Hello, World!' on paper,"
// "type 'Hello, World!' on typewriter," etc.
// All of these will work, and the typewriter may be
// direct or indirect, depending on how the input was
// structured. So we're going to use a broad hook:
// doType is called any time the verb type is used on
// the typewriter, regardless of direct / indirect,
// and we're going to check if the typewriter has paper in it.
// See https://adventurejs.com/doc/Scripting_VerbHooks.html
// for more info on verb hooks.
doType: function () {
if (this.hasContents("in")) {
// Paper is the only class that can be put in Typewriter
// so if it's not empty, it's got a piece of paper in it
// and we can confidently refer to paper in our appended
// output.
WritingDemo.appendTurn(`Now try reading the paper. `);
WritingDemo.scorecard.completeEvent("type on paper");
} else {
// The typewriter is empty so let's append the default
// verb message to help inform the player.
WritingDemo.appendTurn(`{We} might try putting a piece of paper in it. `);
}
},
});
WritingDemo.createAsset({
class: "Thing",
name: "small placard",
place: { on: "rolltop desk" },
// See how this placard description uses custom HTML/CSS.
// We defined the CSS for this style inside the Styles.css
// file that loads with this game. You can load CSS
// via the html link tag, or embed it in a style tag
// in the HTML page that loads your game.
descriptions: {
look: `{We} see a neat typewritten note.
To use the typewriter,
insert a sheet of paper, use the verb type,
and put quotes around the string to be typed.
type "hello world"
`,
// We want to return the same description whether
// player looks at the placard or reads it, and we
// don't want to duplicate that code, so we set
// placard.descriptions.read to point to
// placard.descriptions.look
read: function () {
return this.descriptions.look;
},
// Sometimes we use ()=> arrow functions, but in this
// case, in order to get the right scope when we refer
// to this.descriptions, we need to use a standard function.
},
dov: { read: true },
});
// Scorecard.js
// ----------
/*global adventurejs WritingDemo*/
// Scoring
WritingDemo.scorecard.set({
// This is how you set score events for your game.
// You can add as few or as many as you like,
// and set points to whatever number you like.
// The names are up to you, so set them however you like.
// See http://adventurejs.com/doc/Scripting_Scorecard.html
// for more info.
score_events: {
"write on whiteboard": 1,
"erase whiteboard": 1,
"write on blackboard": 1,
"erase blackboard": 1,
"type on paper": 1,
"write on paper": 1,
"erase paper": 1,
// You can also assign "bonus" points. These won't be
// counted in the total, allowing player to earn a
// score like 110/100.
"try to climb shelves": {
points: 1,
bonus: true,
// Customize the score message by setting message
// to a string or array or function.
message: "[ ** {We} got a bonus point! ** ]",
},
},
});
Source files
write verb logic
Verb logic falls into a few recognizable patterns.
Direction verbs tend to be simple and redirect to
tryTravel()
. Manipulation verbs
test whether one asset is allowed
to interact with another asset. Locomotion verbs test
the player's current ability to move in a specified way.
Many verbs are similar,
but no two verbs are identical. Each verb has its quirks.
If you would like to learn more about general verb logic,
we recommend you see the
Verb Anatomy and
Verb Process pages.
Verb phases and
verb actions /
reactions
offer various hooks to customize verb behavior.
If you find that you want still more flexibility,
you may want to investigate the
patchVerb
method, which lets you replace entire blocks of verb code.
You can also
write verbs from scratch
if you're so inclined.
See
Modify Verbs
for a complete list of verb modification methods.
The following sections provide information that is specific to the
verb write
, though they include many
features which are common to most verbs.
- Verb Demo
- Sentence Structures help filter player input by defining what sentence structures
write
can handle. - Verb Phrases describe the direct and indirect objects that
write
can handle. - Verb Subscriptions enable
write
to act on specific assets, and provide a collection of properties for customizing those interactions. - Verb Phases offer a broad method for authors to hook into default logic and override it with custom code.
- Verb Actions offer a surgical method for authors to hook into
write
's default logic and inject custom code. - Verb Reactions are Verb Actions that occur as secondary effects of successfully applying
write
. - Verb Params contain properties that are distinct to
write
. Not all verbs have params. - Verb Methods lists the methods that
write
inherits from the Verb class. - Verb Properties lists the properties that
write
inherits from the Verb class.
write sequencing
write sentence structures
accepts_structures: [
"verb noun",
"verb preposition noun",
"verb noun preposition noun",
"verb preposition noun preposition noun",
"verb noun preposition noun preposition noun"
]
The parser uses multiple filtering methods to try to channel player input into useable tokens. Sentence structures are defined for each verb in order to narrow down the input that the verb can handle. For example, the verb "hit" might accept "verb noun" as in "hit troll", or "verb noun preposition noun" as in "hit troll with sword", whereas an intransitive verb like "jump" might accept "verb" as a complete sentence. This helps to filter player input. Input that isn't accepted will return a warning to the player.
A note about adverbs: though the parser does handle some adverbs, such as "carefully examine tiara" and "turn left", it excludes them from consideration in sentence structures. Due to the slipperyness of the English language, an adverb can appear in multiple positions in a sentence while still describing the same verb, which presents enough possible word combinations to make sentence structures less useful as a filtering tool. Instead, the parser puts adverbs aside and handles them separately.
- It is possible for authors to modify a verb's structures through the use of patchVerb.
- To learn more about modifying verbs, see Modify Verbs.
write phrases
phrase1:
{
accepts_noun: true,
requires_noun: true,
noun_must_be:
{
known: true,
present: true,
visible: true,
reachable: true,
},
accepts_preposition: true,
preposition_must_be: ["on", "with"],
},
phrase2:
{
accepts_noun: true,
requires_noun: true,
noun_must_be:
{
known: true,
present: true,
visible: true,
reachable: true,
prefer_carried_if_ambiguous: true,
},
accepts_preposition: true,
requires_preposition: true,
preposition_must_be: ["on", "with"],
},
phrase3:
{
accepts_noun: true,
requires_noun: true,
noun_must_be:
{
known: true,
present: true,
visible: true,
reachable: true,
prefer_carried_if_ambiguous: true,
},
accepts_preposition: true,
requires_preposition: true,
preposition_must_be: ["on", "with"],
},
The AdventureJS parser uses multiple filtering methods to try to interpret player input. A phrase usually consists of a noun and/or a preposition that can be handled as a direct or indirect object. Each verb defines a unique set of phrases depending on what its logic can handle. Verbs may handle zero, one, two, or three verbs. The nested noun_must_be object sets conditional qualifiers for nouns to help narrow down assets that the verb might act upon. Input that isn't accepted will return a warning to the player.
- It is possible for authors to modify a verb's phrases through the use of patchVerb.
- To see a list of properties that can be set for phrases, see the Phrase class.
- To see a list of properties that can be set for phrase.noun_must_be, see the NounMustBe class.
- To learn more about modifying verbs, see Modify Verbs.
write verb phases
Verb phases are parts of
verb subscriptions that
allow authors to override how write
is applied
to any specific asset.
This is a broad method for customizing verb/noun interactions on a per-asset
basis. For example, an author might supply completely different logic
for "throw feather" vs "throw baseball" vs "throw anvil".
When write
is applied to an asset, it attempts to run
a sequence of methods. All verbs have a do()
method,
and for most verbs, do()
acts as a sequencer that moves the verb
through six distinct sub-methods, or phases:
doBeforeTry
,
doTry
,
doAfterTry
,
doBeforeSuccess
,
doSuccess
and
doAfterSuccess
.
Each phase serves a specific purpose.
doTry
handles all the default conditional logic to determine whether a verb can be applied to an asset: ie, is the asset present, visible, reachable, etc?doSuccess
handles state changes and printing messages back to the player.- The other four phases,
doBeforeTry
,doAfterTry
,doBeforeSuccess
anddoAfterSuccess
have no default logic. Instead they offer hooks for the author to inject custom code anywhere in the life cycle of the verb action.
See below for examples of how to use verb phases for write
.
do
doBeforeTry
MyGame.createAsset({
class: "Thing",
name: "This Asset",
dov: {
write: {
doBeforeTry: function( params )
{
let msg = `You're about to try to write ${this.articlename}. `;
this.game.print(msg);
return;
},
},
},
});
doTry
doAfterTry
MyGame.createAsset({
class: "Thing",
name: "This Asset",
dov: {
write: {
doAfterTry: function( params )
{
let msg = `You just tried to write ${this.articlename}! `;
this.game.print(msg);
return;
},
},
},
});
doBeforeSuccess
MyGame.createAsset({
class: "Thing",
name: "This Asset",
dov: {
write: {
doBeforeSuccess: function( params )
{
let msg = `You're about to succeed in performing write on ${this.articlename}. `;
this.game.print(msg);
return;
},
},
},
});
doSuccess
doAfterSuccess
MyGame.createAsset({
class: "Thing",
name: "This Asset",
dov: {
write: {
doAfterSuccess: function( params )
{
let msg = `You succeeded in performing write on ${this.articlename}. `;
this.game.print(msg);
return;
},
},
},
});
Expand for example
For example, consider the verb "take" as applied to this singing sword. Imagine that an author wants the game to print a custom message when the player tries to take the sword, and a different message when the player succeeds in taking it.
MyGame.createAsset({
class: "Sword",
name: "singing sword",
dov: {
take:
{
doAfterTry: function( params )
{
let msg = "The sword begins to vibrate as your hand curls around its haft. ";
MyGame.print( msg );
},
doAfterSuccess: function( params )
{
let msg = "The sword bursts into song in your hand. ";
MyGame.print( msg );
},
},
},
});
Note that verb subscriptions are set distinctly for direct objects and indirect objects. All of the prior examples show verb phases applied to direct object verb subscriptions. Verb phases can also be applied to indirect object subscriptions. For example, perhaps our swinging sword had to be removed from a stone. We might want to hook into the stone's indirect object verb subscription for "remove".
MyGame.createAsset({
class: "Thing",
name: "stone",
iov: {
remove:
{
doBeforeTry: function( params )
{
let msg = "Will the stone judge you worthy enough to remove the sword? "
MyGame.print( msg );
},
doAfterSuccess: function( params )
{
let msg = "With the sword removed, the stone bursts into rubble! ";
MyGame.print( msg );
this.destroy();
},
},
},
});
- To learn more, see Verb Phases.
- Verb Phases are related to but distinct from Verb Actions, which offers a more surgical method to hook into the doTry and doSuccess phases, on a per object basis.
write verb actions
These verb actions are available for the verb write
.
Expand any item to see a code example.
If write is called with only a direct object, as in
"write lantern", the
Verb actions can have nested functions for specific asset
interactions. If
If write is called with only a direct object, as in
"light lantern", the
Verb actions can have nested functions for specific asset interactions.
If doWriteThis is found to be an object rather than a function,
the If write is called with a preposition and a direct object,
the
Verb actions can have nested functions for specific asset interactions.
If If write is called with a preposition and a direct object,
the
Verb actions can have nested functions for specific asset interactions.
If first_thing.doWrite[Preposition]This is found to be an object
rather than a function,
the
If write is called with a direct object, a preposition,
and an indirect object, as in "light lantern with candle",
the
Verb actions can have nested functions for specific asset interactions.
If
If write is called with a direct object, a preposition,
and an indirect object, as in "light lantern with candle",
the
Verb actions can have nested functions for specific asset interactions.
If
If write is called with a preposition + a direct object
+ a preposition + an indirect object, as in
"write from lantern to candle",
the
Verb actions can have nested functions for specific asset interactions.
If
If write is called with a preposition + a direct object
+ a preposition + an indirect object, as in
"write from lantern to candle",
the
Verb actions can have nested functions for specific asset interactions.
If
If write is called with "verb noun preposition noun preposition noun",
as in "move rook from black square to white square",
the
Verb actions can have nested functions for specific asset interactions.
If
If write is called with "verb noun preposition noun preposition noun",
as in "move rook from black square to white square",
the
Verb actions can have nested functions for specific asset interactions.
If
tryWriteThis
verb.handleActions()
method
looks for direct_object.tryWriteThis
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteThis: function (params) {
let msg = 'Called verb action first_thing.tryWriteThis()';
MyGame.print(msg);
},
});
direct_object.tryWriteThis
is found to be an object rather than a function, the
verb.handleActions()
method checks the object
for a nested function that matches the player asset's name.
(Since no indirect object was given, the player is assumed
to be the indirect object.) For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteThis: {
"My Hero": function (params) {
let msg = 'Called verb action first_thing.tryWriteThis["My Hero"]()';
MyGame.print(msg);
}
},
});
doWriteThis
verb.handleActions()
method
looks for direct_object.doWriteThis()
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteThis: function (params) {
let msg = 'Called verb action first_thing.doWriteThis()';
MyGame.print(msg);
},
});
verb.handleActions()
method checks the object for a nested
function using the player asset's name. (Since no indirect object was
given, the player is assumed to be the indirect object.)
For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteThis: {
"My Hero": function (params) {
let msg = 'Called verb action first_thing.doWriteThis["My Hero"]()';
MyGame.print(msg);
}
},
});
tryWrite[Preposition]This
verb.handleActions()
method checks the direct object for a
verb action in the form of direct_object.tryWrite[Preposition]This.
This example uses "with" as the preposition, but any preposition
can be set with a unique function.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteWithThis: function (params) {
let msg = 'Called verb action first_thing.tryWriteWithThis()';
MyGame.print(msg);
},
});
first_thing.tryWrite[Preposition]This
is found to be an
object rather than a function,
the verb.handleActions()
method checks the object for a nested
function using the player asset's name. (Since no indirect object was
given, the player is assumed to be the indirect object.)
For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteWithThis: {
"My Hero": function (params) {
let msg = 'Called verb action first_thing.tryWriteWithThis["My Hero"]()';
MyGame.print(msg);
}
},
});
doWrite[Preposition]This
verb.handleActions()
method checks the direct object for a
verb action in the form of direct_object.doWrite[Preposition]This.
This example uses "with" as the preposition, but any preposition
can be set with a unique function.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteWithThis: function (params) {
let msg = 'Called verb action first_thing.doWriteWithThis()';
MyGame.print(msg);
},
});
verb.handleActions()
method checks the object for a nested
function using the player asset's name. (Since no indirect object was
given, the player is assumed to be the indirect object.)
For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteWithThis: {
"My Hero": function (params) {
let msg = 'Called verb action first_thing.doWriteWithThis["My Hero"]()';
MyGame.print(msg);
}
},
});
tryWriteThis[Preposition]That +
tryWriteThat[Preposition]This
verb.handleActions()
method looks for
direct_object.tryWriteThisWithThat
and
indirect_object.tryWriteThatWithThis
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteThisWithThat: function (params) {
let msg = 'Called verb action first_thing.tryWriteThisWithThat()';
MyGame.print(msg);
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
tryWriteThatWithThis: function (params) {
let msg = 'Called verb action second_thing.tryWriteThatWithThis()';
MyGame.print(msg);
},
});
first_thing.tryWriteThisWithThat
is found to be an
object rather than a function, the verb.handleActions()
looks for first_thing.tryWriteThisWithThat["Second Thing"]()
.
The indirect object will also be checked for
second_thing.tryWriteThatWithThis["First Thing"]()
.
The two methods are equivalent. Which to use is purely up to
author's choice. For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteThisWithThat: {
"Second Thing": function (params) {
let msg = 'Called verb action first_thing.tryWriteThisWithThat["Second Thing"]()';
MyGame.print(msg);
}
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
tryWriteThatWithThis: {
"First Thing": function (params) {
let msg = 'Called verb action second_thing.tryWriteThatWithThis["First Thing"]()';
MyGame.print(msg);
}
},
});
doWriteThis[Preposition]That +
doWriteThat[Preposition]This
verb.handleActions()
method looks for
direct_object.doWriteThisWithThat
and
indirect_object.doWriteThatWithThis
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteThisWithThat: function (params) {
let msg = 'Called verb action first_thing.doWriteThisWithThat()';
MyGame.print(msg);
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
doWriteThatWithThis: function (params) {
let msg = 'Called verb action second_thing.doWriteThatWithThis()';
MyGame.print(msg);
},
});
first_thing.doWriteThisWithThat
is found to be an
object rather than a function, the verb.handleActions()
looks for first_thing.doWriteThisWithThat["Second Thing"]()
.
The indirect object will also be checked for
second_thing.doWriteThatWithThis["First Thing"]()
.
The two methods are equivalent. Which to use is purely up to
author's choice. For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteThisWithThat: {
"Second Thing": function (params) {
let msg = 'Called verb action first_thing.doWriteThisWithThat["Second Thing"]()';
MyGame.print(msg);
}
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
doWriteThatWithThis: {
"First Thing": function (params) {
let msg = 'Called verb action second_thing.doWriteThatWithThis["First Thing"]()';
MyGame.print(msg);
}
},
});
tryWrite[Preposition]This[Preposition]That +
tryWrite[Preposition]That[Preposition]This
verb.handleActions()
method looks for
direct_object.tryWriteFromThisToThat
and
indirect_object.tryWriteFromThatToThis
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteFromThisToThat: function (params) {
let msg = 'Called verb action first_thing.tryWriteFromThisToThat()';
MyGame.print(msg);
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
tryWriteFromThatToThis: function (params) {
let msg = 'Called verb action second_thing.tryWriteFromThatToThis()';
MyGame.print(msg);
},
});
first_thing.tryWriteFromThisToThat
is found to be an
object rather than a function, the verb.handleActions()
looks for first_thing.tryWriteFromThatToThis["Second Thing"]()
.
The indirect object will also be checked for
second_thing.tryWriteFromThisToThat["First Thing"]()
.
The two methods are equivalent. Which to use is purely up to
author's choice. For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteFromThisToThat: {
"Second Thing": function (params) {
let msg = 'Called verb action first_thing.tryWriteFromThisToThat["Second Thing"]()';
MyGame.print(msg);
}
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
tryWriteFromThatToThis: {
"First Thing": function (params) {
let msg = 'Called verb action second_thing.tryWriteFromThatToThis["First Thing"]()';
MyGame.print(msg);
}
},
});
doWrite[Preposition]This[Preposition]That +
doWrite[Preposition]That[Preposition]This
verb.handleActions()
method looks for
direct_object.doWriteFromThisToThat
and
indirect_object.doWriteFromThatToThis
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteFromThisToThat: function (params) {
let msg = 'Called verb action first_thing.doWriteFromThisToThat()';
MyGame.print(msg);
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
doWriteFromThatToThis: function (params) {
let msg = 'Called verb action second_thing.doWriteFromThatToThis()';
MyGame.print(msg);
},
});
first_thing.doWriteFromThisToThat
is found to be an
object rather than a function, the verb.handleActions()
looks for first_thing.doWriteFromThatToThis["Second Thing"]()
.
The indirect object will also be checked for
second_thing.doWriteFromThisToThat["First Thing"]()
.
The two methods are equivalent. Which to use is purely up to
author's choice. For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteFromThisToThat: {
"Second Thing": function (params) {
let msg = 'Called verb action first_thing.doWriteFromThisToThat["Second Thing"]()';
MyGame.print(msg);
}
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
doWriteFromThatToThis: {
"First Thing": function (params) {
let msg = 'Called verb action second_thing.doWriteFromThatToThis["First Thing"]()';
MyGame.print(msg);
}
},
});
tryWriteThis[Preposition]That[Preposition]Other +
tryWriteThat[Preposition]This[Preposition]Other
verb.handleActions()
method looks for
direct_object.tryWriteThisFromThatToOther
and
indirect_object.tryWriteThatFromThisToOther
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteThisFromThatToOther: function (params) {
let msg = 'Called verb action first_thing.tryWriteThisFromThatToOther()';
MyGame.print(msg);
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
tryWriteThatFromThisToOther: function (params) {
let msg = 'Called verb action second_thing.tryWriteThatFromThisToOther()';
MyGame.print(msg);
},
});
first_thing.tryWriteThisFromThatToOther
is found to be an
object rather than a function, the verb.handleActions()
looks for first_thing.tryWriteThisFromThatToOther["Second Thing"]()
.
In the case of an input like this with three nouns,
verb.handleActions()
will also look a level deeper.
This allows for assigning verb actions to very specific combinations.
For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
tryWriteThisFromThatToOther: {
"Second Thing": {
"Third Thing": function (params) {
let msg = 'Called verb action first_thing.tryWriteThisFromThatToOther["Second Thing"]["Third Thing"]()';
MyGame.print(msg);
}
}
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
tryWriteThatFromThisToOther: {
"First Thing": {
"Third Thing": function (params) {
let msg = 'Called verb action second_thing.tryWriteThisFromThatToOther["First Thing"]["Third Thing"]()';
MyGame.print(msg);
}
}
},
});
doWriteThis[Preposition]That[Preposition]Other +
doWriteThat[Preposition]This[Preposition]Other
verb.handleActions()
method looks for
direct_object.doWriteThisFromThatToOther
and
indirect_object.doWriteThatFromThisToOther
.
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteThisFromThatToOther: function (params) {
let msg = 'Called verb action first_thing.doWriteThisFromThatToOther()';
MyGame.print(msg);
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
doWriteThatFromThisToOther: function (params) {
let msg = 'Called verb action second_thing.doWriteThatFromThisToOther()';
MyGame.print(msg);
},
});
first_thing.doWriteThisFromThatToOther
is found to be an
object rather than a function, the verb.handleActions()
looks for first_thing.doWriteThisFromThatToOther["Second Thing"]()
.
In the case of an input like this with three nouns,
verb.handleActions()
will also look a level deeper.
This allows for assigning verb actions to very specific combinations.
For example:
MyGame.createAsset({
class: "Thing",
name: "First Thing",
doWriteThisFromThatToOther: {
"Second Thing": {
"Third Thing": function (params) {
let msg = 'Called verb action first_thing.doWriteThisFromThatToOther["Second Thing"]["Third Thing"]()';
MyGame.print(msg);
}
}
},
});
MyGame.createAsset({
class: "Thing",
name: "Second Thing",
doWriteThatFromThisToOther: {
"First Thing": {
"Third Thing": function (params) {
let msg = 'Called verb action second_thing.doWriteThisFromThatToOther["First Thing"]["Third Thing"]()';
MyGame.print(msg);
}
}
},
});
WHY SO MANY???
Verb actions provide hooks that allow authors to inject custom code in response to specific combinations of verb/preposition/noun. There are a lot of them and clearly some are redundant; in its defense, it's a deliberate effort to offer a menu of precise injection points for authors' custom code. To use a verb action, just use the verb action name as a method on any asset. Below is a generic example of how to code a verb action.
Expand for example
In this example, the pistol asset has two verb actions.
-
pistol.doShootThis()
will be called when a player inputs "shoot pistol". -
pistol.doShootThatWithThis.television()
will be called when a player inputs "shoot television with pistol".
MyGame.createAsset({
class: "Player",
name: "Elvis",
});
MyGame.createAsset({
class: "Weapon",
name: "pistol",
doShootThis: {
let msg = `You fire the pistol! BANG! `;
MyGame.print(msg);
},
doShootThatWithThis:{
"television": function {
let msg = `You fire the pistol at the television! BANG!
The television explodes with sparks and a screech of static. `;
MyGame.print(msg);
},
},
});
MyGame.createAsset({
class: "Electronics",
name: "television",
});
Verb actions are called by the verb.handleActions()
method, which looks for those nested functions and calls
whatever function it finds.
Each verb has a unique set of actions, which mirror the
sentence structures the verb
can handle. For instance, the verb lock
handles "verb noun" and "verb noun preposition noun",
and so it handles tryLockThis
and
doLockThis
and
tryLockThisWithThat
and
doLockThisWithThat
.
The difference between try
actions and
do
actions is one of timing.
try
actions fire immediately
before a verb's doTry phase,
which provides an opportunity to supersede a verb's
default conditional logic before it tests whether the verb
can be applied to the assets.
do
actions fire immediately
before a verb's doSuccess phase,
which provides an opportunity to supersede or append the verb's
state changes and output to the player.
It's common for sentence structures to be mutated during
a verb's doTry
phase, as doTry
may reorder a player's input to make it conform with the verb's logic.
This means that the try
and do
actions may differ within the same turn. You can check the
browser's Javascript console to see which actions are being
called.
- See Verb Actions to learn more.
- In addition to verb actions, there are verb reactions, which are a set of non-verb-specific hooks that fire as side effects of a verb's doSuccess phase. See Verb Reactions for a complete list of them.
- Verb actions and reactions are related to but distinct from Verb Phases, which allow authors to broadly override entire phases of a verb.
write verb reactions
Verb reactions
provide hooks that allow authors to inject custom code
into side effects caused by successful verb operations.
Consider the verb drop
.
Inputting "drop lantern" will result in two events –
removing the lantern from the player and moving it to the room –
which causes these four verb reactions:
• lantern.doRemoveThisFromThat(player)
• player.doRemoveThatFromThis(lantern)
• lantern.doMoveThisToThat(room)
• room.doMoveThatToThis(lantern)
There are four reactions because each asset in the interaction is checked for custom code pertaining to the other. This may seem redundant, but it's done in a deliberate effort to provide flexibility to authors. If you prefer to attach custom code to the lantern, you can. If you prefer to attach custom code to the player, you can. You're welcome to organize your code in whichever way serves you best.
Expand for example
In this example, imagine that an author would like
the game to print a custom message whenever Elvis enters or leaves
the building, regardless of what verb is used. Authors
can hook into any of the doRemoveThisFromThat
,
doRemoveThatFromThis
, doMoveThisToThat
,
or doMoveThatToThis
verb reactions.
Below is a generic example of how to code a verb reaction.
MyGame.createAsset({
class: "Player",
name: "Elvis",
}),
MyGame.createAsset({
class: "Room",
name: "The Building",
doMoveThatToThis:
{
"Elvis": function()
{
MyGame.print("Elvis has entered The Building! ");
}
},
doRemoveThatFromThis:
{
"Elvis": function()
{
MyGame.print("Elvis has left The Building! ");
}
},
}),
- Verb reactions aren't specific to any particular verb; they may be called by many verbs. See Verb Reactions for a complete list of them.
- Verb reactions work the same way as Verb Actions. The only differences are that verb reactions are non-specific and only fire at the end of a verb's doSuccess phase.
- Verb actions and reactions are related to but distinct from Verb Phases, which allow authors to broadly override entire phases of a verb.
write subscriptions
An asset must be subscribed to a verb for that verb to act upon that asset (with some exceptions). Though verbs are universal, each asset's verb subscriptions are distinct objects that can be used to customize how a given verb interacts with a given asset. To say it another way, a verb subscription is a collection of properties that defines how a verb should be applied to an asset; which allow authors to override a verb's default behaviors on a per-asset basis.
It's important to note that verb subscriptions need to be declared as direct or indirect, depending on whether the asset will be used as a direct object or indirect object. In the case of "unlock lock with key", the lock is the direct object and the key is the indirect object, and each asset needs to be subscribed to unlock in the appropriate way. (It's allowed, and a common pattern, to subscribe assets directly and indirectly to the same verb.)
Expand for example
MyGame.createAsset({
class: "Lock",
name: "lock",
dov: { unlock: true },
});
MyGame.createAsset({
class: "Key",
name: "key",
iov: { unlock: true },
});
As shown in the above example, dov: { unlock: true }
is the minimum that is required to subscribe an asset to a verb. However, verb subscriptions have many properties that can be used to customize how this verb is applied to this asset. (Setting any property eliminates the need to set verb: true
. ) Below is a list of verb subscription properties that authors may find useful.
automatically
allows for some verbs to be performed automatically if context calls for it; for example, when unlocking a door in order to pass through it. This takes precedence over global settings.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { automatically: true } }, });
automatically_after_use
if automatically is set true, this sets it so that a verb can only be applied automatically after a player has already used it manually. This is to prevent automatic use of tools from breaking puzzles. For example, imagine one door with many keys but only one that works; if choosing the right key is part of the puzzle, this option prevents players from simply saying "unlock door" and having the right key automatically selected for them.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { automatically_after_use: true } }, });
doBeforeTry
Verb phases provide methods to override default verb behaviors. See the verb phases section on this page to learn more aboutwrite
's verb phases.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { doBeforeTry: function (e) { console.log("write.doBeforeTry"); }, } }, });
doAfterTry
Verb phases provide methods to override default verb behaviors. See the verb phases section on this page to learn more aboutwrite
's verb phases.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { doAfterTry: function (e) { console.log("write.doAfterTry"); }, } }, });
doBeforeSuccess
Verb phases provide methods to override default verb behaviors. See the verb phases section on this page to learn more aboutwrite
's verb phases.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { doBeforeSuccess: function (e) { console.log("write.doBeforeSuccess"); }, } }, });
doAfterSuccess
Verb phases provide methods to override default verb behaviors. See the verb phases section on this page to learn more aboutwrite
's verb phases.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { doAfterSuccess: function (e) { console.log("write.doAfterSuccess"); }, } }, });
enabled
allows changing the state of an asset's responsiveness to a given verb. If set false, a subscribed asset will not respond to the verb. This is useful for temporarily disabling verbs for specific assets; for example, if you had a door that could not be unlocked until another action was completed. Authors can enable or disable an individual verb subscription viaasset.setDOV(verbname)
andasset.unsetDOV(verbname)
Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { enabled: true } }, });
on_success
is an optional parameter. It is set as a string by default, but authors may provide a string or array or function to be served by getStringOrArrayOrFunction(). The resulting string will be appended to the verb's default success message.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { on_success: "You write the thing. " } }, });
on_first_success
is an optional parameter. It is set as a string by default, but may provide a string or array or function to be served by getStringOrArrayOrFunction(). The resulting string will be appended to the verb's default success message the first time it is applied to this asset.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { on_first_success: "You write the thing the first time. " } }, });
on_failure
is an optional parameter. It is set as a string by default, but may provide a string or array or function to be served by getStringOrArrayOrFunction(). The resulting string will be appended to the verb's default failure message.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { on_failure: "You failed to write the thing. " } }, });
on_first_failure
is an optional parameter. It is set as a string by default, but may provide a string or array or function to be served by getStringOrArrayOrFunction(). The resulting string will be appended to the verb's default failure message the first time it is applied to this asset.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { on_first_failure: "You failed to write the thing the first time. " } }, });
once
if true, the verb can only be applied once to the asset. The verb subscription will be disabled after use.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { once: true } }, });
then_destroy
allows author to specify that this asset should be destroyed after using. If then_destroy is set, the asset will be destroyed after a single use regardless of how once is set. By default, then_destroy is set to a boolean. It may optionally be set to string or array or function subject to getStringOrArrayOrFunction(). If any of those types are found, they will be called and returned as results.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { then_destroy: true } }, });
with_anything
pertains only to indirect objects. If true, this asset can be used as an indirect object of this verb with any direct object.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", iov: { write: { with_anything: true } }, });
with_assets
allows author to specify particular assets that can interact with this one using the given verb. For example "unlock door with key" where the specified key is the only asset that can unlock door. This works distinctly for direct and indirect verb subscriptions. So, for instance, in "unlock door with key", the door might have a direct object subscription, while the key has an indirect object description.Expand for example
MyGame.createAsset({ class: "Door", name: "gold door", dov: { unlock: { with_assets: [ "gold key" ] } }, }); MyGame.createAsset({ class: "Key", name: "gold key", iov: { unlock: { with_assets: [ "gold door" ] } }, });
with_classes
allows author to specify particular classes that can interact with this asset using the given verb. For example "unlock door with skeleton key" where any instance of the class SkeletonKey can unlock door. This works distinctly for direct and indirect verb subscriptions. So, for instance, in "unlock door with skeleton key", the door might have a direct object subscription, while the key has an indirect object description.Expand for example
MyGame.createAsset({ class: "Door", name: "red door", dov: { unlock: { with_classes: [ "SkeletonKey" ] } }, }); MyGame.createAsset({ class: "SkeletonKey", name: "skeleton key", iov: { unlock: { with_classes: [ "Door", "Chest" ] } }, });
with_nothing
pertains only to direct objects. If true, the specified verb can be applied to the direct object without the use of any indirect object.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { with_nothing: true } }, });
with_params
is used to contain a set of parameters that are specific to this particular verb. For example, plugIn includeswith_params.max_connections
for setting limits on how many other assets this asset can be plugged in to. See the with_params section on this page to learn more aboutwrite
's parameters.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { with_params: { // tool is a writing implement tool: false, // target is a writing surface target: false, } } }, });
with_prepositions
allows author to explicitly permit certain prepositions to be used with a verb on this object. For instance: "knock over umbrella stand" might fail with a message of "you can't knock over the umbrella stand"; settingumbrella_stand.dov.knock.with_prepositions = ["over"]
will allow the action to succeed.Expand for example
MyGame.createAsset({ class: "Thing", name: "universal widget", dov: { write: { with_prepositions: [ "through", "over" ] } }, });
- To learn more about working with verb subscriptions, see Verb Subscriptions.
- These are most, but not all, of the properties of a verb subscription. For full reference, see the VerbSubscription class.
write params
Some verbs may have custom params. When an asset subscribes to such a verb, the verb's params are mirrored in the asset's verb subscription, where they are unique to that asset. To put it another way: while each verb may have a unique set of params, each asset may have its own customized version of those params.
with_params: {
// tool is a writing implement
tool: false,
// target is a writing surface
target: false,
},
For example, consider this setting of the verb plugIn:
MyGame.dictionary.verbs.plugIn.with_params.max_connections = 1
By default, assets that can be plugged in will take this setting and can only be plugged in to one other asset. Now imagine that an author wants to create a power cord that needs to be plugged in to both a computer and an outlet. The author can achieve that by customizing the cord's subscription to plugIn.
Expand for example
MyGame.createAsset({
class: "Cable",
name: "power cord",
dov: { plugIn: { with_assets: ['computer','outlet'], with_params: { max_connections: 2 }, }, },
})
MyGame.createAsset({
class: "Computer",
name: "PC",
iov: { plugIn: { with_assets: ['power cord'], }, },
})
MyGame.createAsset({
class: "ElectricalOutlet",
name: "outlet",
iov: { plugIn: { with_assets: ['power cord'], }, },
})
In this example, the power cord verb subscription's max_connections setting overrides the verb's max_connections setting, allowing the player to plug the power cord into two assets. The computer and the outlet don't have any custom value set for max_connections; they'll receive the default value, meaning they each can have only one asset plugged into them.
- It is possible for authors to modify a verb's params through the use of patchVerb.
- To learn more about modifying verbs, see Modify Verbs.
Private Constructor:
MyGame.createVerb({ "name": "write", [...] });
write is a predefined instance of Verb that gets constructed automatically at runtime. It is defined in the library as a generic object, and then passed to Dictionary#createVerb for construction, validation, and initialization. Because this is predefined, authors should not need to create new instances. For information on modifying predefined Verbs, see Modify Verbs.
- Index
- Methods
- Properties
Index
Methods:
- Inherited from Verb agree
- Inherited from Verb canBeIntransitive
- Inherited from Verb do
- Inherited from Verb doSuccess
- Inherited from Verb doTry
- Inherited from Verb enqueueCollection
- Inherited from Verb getState
- Inherited from Verb handleActions
- Inherited from Verb handleFailure
- Inherited from Verb handleSuccess
- Inherited from Verb hasState
- Inherited from Verb hasStructure
- Inherited from Verb hasVerbSubscriptionConnection
- Inherited from Verb initialize
- Inherited from Verb set
- Inherited from Verb setState
- Inherited from Verb setVerbConnection
- Inherited from Verb tryDestroyAfterUsing
- Inherited from Verb tryDestroyDirectObjectAfterUsing
- Inherited from Verb tryDestroyIndirectObjectAfterUsing
- Inherited from Verb tryPhaseHook
- Inherited from Verb tryToInferIndirectObject
- Inherited from Verb tryToPutThisInThatAspect
- Inherited from Verb unsetVerbConnection
- Inherited from Verb validate
Properties:
- Inherited from Verb accepts_adverbs
- Inherited from Verb accepts_direction
- Inherited from Verb accepts_number
- Inherited from Verb accepts_string
- Inherited from Verb accepts_structures
- Inherited from Verb Overrides from Verb adjectives
- Inherited from Verb allow_iov_on_iov
- Inherited from Verb article
- Inherited from Verb can_span
- Inherited from Verb default_direction
- Inherited from Verb dictionary
- Inherited from Verb direction_preposition
- Inherited from Verb doVerb
- Inherited from Verb doVerbFromThis
- Inherited from Verb doVerbThatFromThis
- Inherited from Verb doVerbThatWithThis
- Inherited from Verb doVerbThis
- Inherited from Verb doVerbThisFromThat
- Inherited from Verb doVerbThisWithThat
- Inherited from Verb doVerbWithThis
- Inherited from Verb enqueue_collections
- Inherited from Verb extends
- Inherited from Verb game
- Inherited from Verb gerund
- Inherited from Verb in_can_mean_on
- Inherited from Verb input_substitutions
- Inherited from Verb is_compass_direction
- Inherited from Verb is_direction
- Inherited from Verb is_relative_direction
- Inherited from Verb let_verb_handle_disambiguation
- Inherited from Verb let_verb_handle_remaining_input
- Inherited from Verb name
- Inherited from Verb Name
- Inherited from Verb override_verb_failure_msg
- Inherited from Verb override_verb_success_msg
- Inherited from Verb past_tense
- Inherited from Verb phrase1
- Inherited from Verb phrase2
- Inherited from Verb phrase3
- Inherited from Verb Overrides from Verb posture
- Inherited from Verb prettyname
- Inherited from Verb related
- Inherited from Verb requires_number
- Inherited from Verb requires_string
- Inherited from Verb state
- Inherited from Verb state_strings
- Inherited from Verb subject_must_be
- Inherited from Verb synonyms
- Inherited from Verb tryVerbFromThis
- Inherited from Verb tryVerbThatFromThis
- Inherited from Verb tryVerbThatWithThis
- Inherited from Verb tryVerbThis
- Inherited from Verb tryVerbThisFromThat
- Inherited from Verb tryVerbThisWithThat
- Inherited from Verb tryVerbWithThis
- Inherited from Verb type
- Inherited from Verb unstate
- Inherited from Verb verb_noun_prep
- Inherited from Verb verb_noun_prep_noun
- Inherited from Verb verb_noun_prep_noun_prep_noun
- Inherited from Verb verb_noun_prep_prep_noun
- Inherited from Verb verb_prep_noun
- Inherited from Verb verb_prep_noun_prep_noun
- Inherited from Verb verb_prep_noun_prep_noun_prep_noun
- Inherited from Verb verb_prep_prep_noun
- Inherited from Verb verb_prep_prep_prep_noun
Methods Collapse all |
agree
agree()
Defined in: adventure/dictionary/Verb.js, line 2895
Inherited from: adventurejs.Verb#agree
canBeIntransitive
canBeIntransitive()
Defined in: adventure/dictionary/Verb.js, line 2631
Inherited from: adventurejs.Verb#canBeIntransitive
do
do()
Defined in: adventure/dictionary/Verb.js, line 1077
Inherited from: adventurejs.Verb#do
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
doSuccess()
Defined in: adventure/dictionary/Verb.js, line 1729
Inherited from: adventurejs.Verb#doSuccess
doTry
doTry()
Defined in: adventure/dictionary/Verb.js, line 1343
Inherited from: adventurejs.Verb#doTry
enqueueCollection
enqueueCollection()
Defined in: adventure/dictionary/Verb.js, line 2295
Inherited from: adventurejs.Verb#enqueueCollection
getState
getState()
Defined in: adventure/dictionary/Verb.js, line 2649
Inherited from: adventurejs.Verb#getState
handleActions
handleActions()
Defined in: adventure/dictionary/Verb.js, line 1358
Inherited from: adventurejs.Verb#handleActions
handleFailure
handleFailure()
Defined in: adventure/dictionary/Verb.js, line 2339
Inherited from: adventurejs.Verb#handleFailure
handleSuccess
handleSuccess()
Defined in: adventure/dictionary/Verb.js, line 2438
Inherited from: adventurejs.Verb#handleSuccess
hasState
hasState()
Defined in: adventure/dictionary/Verb.js, line 2640
Inherited from: adventurejs.Verb#hasState
hasStructure
hasStructure() → {boolean}
Defined in: adventure/dictionary/Verb.js, line 2667
Inherited from: adventurejs.Verb#hasStructure
Returns:
boolean
hasVerbSubscriptionConnection
hasVerbSubscriptionConnection()
Defined in: adventure/dictionary/Verb.js, line 2798
Inherited from: adventurejs.Verb#hasVerbSubscriptionConnection
initialize
initialize()
Defined in: adventure/dictionary/Verb.js, line 2266
Inherited from: adventurejs.Verb#initialize
Todos: How does patchVerb handle initialization?
set
set(props) → {adventurejs.Verb}
Defined in: adventure/dictionary/Verb.js, line 2327
Inherited from: adventurejs.Verb#set
Parameters:
-
props
Object
A generic object containing properties to copy to the DisplayObject instance.
setState
setState()
Defined in: adventure/dictionary/Verb.js, line 2658
Inherited from: adventurejs.Verb#setState
setVerbConnection
setVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 2677
Inherited from: adventurejs.Verb#setVerbConnection
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
Inherited from: adventurejs.Verb#tryDestroyAfterUsing
Parameters:
-
object_of
String -
asset
Object
Returns:
Object
tryDestroyDirectObjectAfterUsing
tryDestroyDirectObjectAfterUsing(asset) → {Boolean|string}
Defined in: adventure/asset/tryDestroyDirectObjectAfterUsing.js, line 6
Inherited from: adventurejs.Verb#tryDestroyDirectObjectAfterUsing
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
tryDestroyIndirectObjectAfterUsing(asset) → {Boolean|string}
Defined in: adventure/asset/tryDestroyIndirectObjectAfterUsing.js, line 6
Inherited from: adventurejs.Verb#tryDestroyIndirectObjectAfterUsing
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
tryPhaseHook
tryPhaseHook(phase) → {*}
Defined in: adventure/dictionary/Verb.js, line 1746
Inherited from: adventurejs.Verb#tryPhaseHook
Parameters:
-
phase
*
Returns:
*
tryToInferIndirectObject
tryToInferIndirectObject(options) → {Object}
Defined in: adventure/dictionary/Verb.js, line 1795
Inherited from: adventurejs.Verb#tryToInferIndirectObject
Parameters:
-
options
Object
An object of options.Properties
-
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. -
context
Object
The subject, usually player, could be an NPC. -
infer_first_use
Boolean
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 2012
Inherited from: adventurejs.Verb#tryToPutThisInThatAspect
Parameters:
-
direct_object
Object -
preposition
String -
indirect_object
Object
Returns:
Object
unsetVerbConnection
unsetVerbConnection()
Defined in: adventure/dictionary/Verb.js, line 2738
Inherited from: adventurejs.Verb#unsetVerbConnection
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 2259
Inherited from: adventurejs.Verb#validate
Properties |
accepts_adverbs
accepts_adverbs :Array
Defined in: adventure/dictionary/Verb.js, line 432
Inherited from: adventurejs.Verb#accepts_adverbs
Default value: []
accepts_direction
accepts_direction :String
Defined in: adventure/dictionary/Phrase.js, line 26
Inherited from: adventurejs.Verb#accepts_direction
accepts_number
accepts_number :String
Defined in: adventure/dictionary/Phrase.js, line 40
Inherited from: adventurejs.Verb#accepts_number
accepts_string
accepts_string :String
Defined in: adventure/dictionary/Phrase.js, line 19
Inherited from: adventurejs.Verb#accepts_string
accepts_structures
accepts_structures :Array
Defined in: adventure/dictionary/Verb.js, line 426
Inherited from: adventurejs.Verb#accepts_structures
Default value: []
adjectives
adjectives :String
Defined in: adventure/dictionary/Verb.js, line 299
Overrides from: adventurejs.Verb#adjectives
allow_iov_on_iov
allow_iov_on_iov :Array
Defined in: adventure/dictionary/Verb.js, line 500
Inherited from: adventurejs.Verb#allow_iov_on_iov
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 388
Inherited from: adventurejs.Verb#article
Default value: false
can_span
can_span :String
Defined in: adventure/dictionary/Verb.js, line 236
Inherited from: adventurejs.Verb#can_span
default_direction
default_direction :String
Defined in: adventure/dictionary/Verb.js, line 163
Inherited from: adventurejs.Verb#default_direction
Default value: ""
dictionary
dictionary :Object
Defined in: adventure/dictionary/Verb.js, line 143
Inherited from: adventurejs.Verb#dictionary
Default value: {}
direction_preposition
direction_preposition :Boolean
Defined in: adventure/dictionary/Verb.js, line 400
Inherited from: adventurejs.Verb#direction_preposition
Default value: ""
doVerb
doVerb :Getter
Defined in: adventure/dictionary/Verb.js, line 596
Inherited from: adventurejs.Verb#doVerb
doVerbFromThis
doVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 612
Inherited from: adventurejs.Verb#doVerbFromThis
doVerbThatFromThis
doVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 652
Inherited from: adventurejs.Verb#doVerbThatFromThis
doVerbThatWithThis
doVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 636
Inherited from: adventurejs.Verb#doVerbThatWithThis
doVerbThis
doVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 604
Inherited from: adventurejs.Verb#doVerbThis
doVerbThisFromThat
doVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 644
Inherited from: adventurejs.Verb#doVerbThisFromThat
doVerbThisWithThat
doVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 628
Inherited from: adventurejs.Verb#doVerbThisWithThat
doVerbWithThis
doVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 620
Inherited from: adventurejs.Verb#doVerbWithThis
enqueue_collections
enqueue_collections :Array
Defined in: adventure/dictionary/Verb.js, line 487
Inherited from: adventurejs.Verb#enqueue_collections
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
Inherited from: adventurejs.Verb#extends
Default value: ""
game
game :Object
Defined in: adventure/dictionary/Verb.js, line 136
Inherited from: adventurejs.Verb#game
Default value: {}
gerund
gerund :String
Defined in: adventure/dictionary/Verb.js, line 200
Inherited from: adventurejs.Verb#gerund
in_can_mean_on
in_can_mean_on :Boolean
Defined in: adventure/dictionary/Verb.js, line 355
Inherited from: adventurejs.Verb#in_can_mean_on
Default value: false
input_substitutions
input_substitutions :Object
Defined in: adventure/dictionary/Verb.js, line 438
Inherited from: adventurejs.Verb#input_substitutions
Default value: {}
is_compass_direction
is_compass_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 371
Inherited from: adventurejs.Verb#is_compass_direction
Default value: false
is_direction
is_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 364
Inherited from: adventurejs.Verb#is_direction
Default value: false
is_relative_direction
is_relative_direction :Boolean
Defined in: adventure/dictionary/Verb.js, line 379
Inherited from: adventurejs.Verb#is_relative_direction
Default value: false
let_verb_handle_disambiguation
let_verb_handle_disambiguation :Boolean
Defined in: adventure/dictionary/Verb.js, line 335
Inherited from: adventurejs.Verb#let_verb_handle_disambiguation
Default value: false
let_verb_handle_remaining_input
let_verb_handle_remaining_input :Boolean
Defined in: adventure/dictionary/Verb.js, line 344
Inherited from: adventurejs.Verb#let_verb_handle_remaining_input
Default value: false
name
name :String
Defined in: adventure/dictionary/Verb.js, line 179
Inherited from: adventurejs.Verb#name
Default value: ""
Name
Name :Getter
Defined in: adventure/dictionary/Verb.js, line 520
Inherited from: adventurejs.Verb#Name
Default value: []
override_verb_failure_msg
override_verb_failure_msg :String
Defined in: adventure/dictionary/Verb.js, line 450
Inherited from: adventurejs.Verb#override_verb_failure_msg
Default value: undefined
override_verb_success_msg
override_verb_success_msg :String
Defined in: adventure/dictionary/Verb.js, line 459
Inherited from: adventurejs.Verb#override_verb_success_msg
Default value: undefined
past_tense
past_tense :String
Defined in: adventure/dictionary/Verb.js, line 194
Inherited from: adventurejs.Verb#past_tense
phrase1
phrase1 :Object
Defined in: adventure/dictionary/Verb.js, line 408
Inherited from: adventurejs.Verb#phrase1
Default value: {}
phrase2
phrase2 :Object
Defined in: adventure/dictionary/Verb.js, line 414
Inherited from: adventurejs.Verb#phrase2
Default value: {}
phrase3
phrase3 :Object
Defined in: adventure/dictionary/Verb.js, line 420
Inherited from: adventurejs.Verb#phrase3
Default value: {}
posture
posture :String
Defined in: adventure/dictionary/Verb.js, line 206
Overrides from: adventurejs.Verb#posture
prettyname
prettyname :String
Defined in: adventure/dictionary/Verb.js, line 186
Inherited from: adventurejs.Verb#prettyname
related
requires_number
requires_number :String
Defined in: adventure/dictionary/Phrase.js, line 47
Inherited from: adventurejs.Verb#requires_number
requires_string
requires_string :String
Defined in: adventure/dictionary/Phrase.js, line 33
Inherited from: adventurejs.Verb#requires_string
state
state :String
Defined in: adventure/dictionary/Verb.js, line 247
Inherited from: adventurejs.Verb#state
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 267
Inherited from: adventurejs.Verb#state_strings
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 315
Inherited from: adventurejs.Verb#subject_must_be
Default value: {}
synonyms
synonyms :Getter/Setter
Defined in: adventure/dictionary/Verb.js, line 660
Inherited from: adventurejs.Verb#synonyms
Default value: []
tryVerbFromThis
tryVerbFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 556
Inherited from: adventurejs.Verb#tryVerbFromThis
tryVerbThatFromThis
tryVerbThatFromThis :Getter
Defined in: adventure/dictionary/Verb.js, line 588
Inherited from: adventurejs.Verb#tryVerbThatFromThis
tryVerbThatWithThis
tryVerbThatWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 572
Inherited from: adventurejs.Verb#tryVerbThatWithThis
tryVerbThis
tryVerbThis :Getter
Defined in: adventure/dictionary/Verb.js, line 540
Inherited from: adventurejs.Verb#tryVerbThis
tryVerbThisFromThat
tryVerbThisFromThat :Getter
Defined in: adventure/dictionary/Verb.js, line 580
Inherited from: adventurejs.Verb#tryVerbThisFromThat
tryVerbThisWithThat
tryVerbThisWithThat :Getter
Defined in: adventure/dictionary/Verb.js, line 564
Inherited from: adventurejs.Verb#tryVerbThisWithThat
tryVerbWithThis
tryVerbWithThis :Getter
Defined in: adventure/dictionary/Verb.js, line 548
Inherited from: adventurejs.Verb#tryVerbWithThis
type
type :String
Defined in: adventure/dictionary/Verb.js, line 151
Inherited from: adventurejs.Verb#type
Default value: ""
unstate
unstate :String
Defined in: adventure/dictionary/Verb.js, line 257
Inherited from: adventurejs.Verb#unstate
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
verb_noun_prep :Array
Defined in: adventure/dictionary/Verb.js, line 726
Inherited from: adventurejs.Verb#verb_noun_prep
Default value: []
verb_noun_prep_noun
verb_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 890
Inherited from: adventurejs.Verb#verb_noun_prep_noun
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 979
Inherited from: adventurejs.Verb#verb_noun_prep_noun_prep_noun
Default value: []
verb_noun_prep_prep_noun
verb_noun_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 937
Inherited from: adventurejs.Verb#verb_noun_prep_prep_noun
Default value: []
verb_prep_noun
verb_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 767
Inherited from: adventurejs.Verb#verb_prep_noun
Default value: []
verb_prep_noun_prep_noun
verb_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 684
Inherited from: adventurejs.Verb#verb_prep_noun_prep_noun
Default value: []
verb_prep_noun_prep_noun_prep_noun
verb_prep_noun_prep_noun_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 1025
Inherited from: adventurejs.Verb#verb_prep_noun_prep_noun_prep_noun
Default value: []
verb_prep_prep_noun
verb_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 808
Inherited from: adventurejs.Verb#verb_prep_prep_noun
Default value: []
verb_prep_prep_prep_noun
verb_prep_prep_prep_noun :Array
Defined in: adventure/dictionary/Verb.js, line 849
Inherited from: adventurejs.Verb#verb_prep_prep_prep_noun
Default value: []