Add More Assets:Collections
Drawers. Windows. Statues.
vs group - use as example silverware - knives, forks, spoons *
Collection provides a way to perform some verbs
on a specific group of related objects. In the example below,
a Desk has three
Drawers. Each drawer can be open or
closed. A player might input something like
examine drawers
. Normally, that would lead to a
disambiguation prompt
such as Which did $(we) mean? 1. The top drawer,
2. the middle drawer, or 3. the bottom drawer?
Here, we've made a collection for the three drawers lets players
refer to the three drawers as one object.
MyGame.createAsset({
class: "Desk",
name: "desk",
place: { in: "Office" },
descriptions: {
look: function()
{
return "It's a heavy wooden desk. It has three drawers
stacked vertically. The top drawer is $( top drawer is| open or| closed ),
the middle drawer is $( middle drawer is| open or| closed ),
and the bottom drawer is $( bottom drawer is| open or| closed )."
},
},
adjectives: "wooden, heavy",
});
MyGame.createAsset({
class: "Drawer",
name: "top drawer",
synonyms: "top desk drawer, top drawer lock, lock",
descriptions: { look: "The top drawer is $( top drawer is| open or| closed ). ", },
adjectives: "desk",
place: { attached: "desk" },
dov: { unlock: { with_assets: ['tiny brass key'], }, },
is: { locked: true, listed_in_parent: false },
});
MyGame.createAsset({
class: "Drawer",
name: "middle drawer",
synonyms: "middle desk drawer",
descriptions: { look: "The middle drawer is $( middle drawer is| open or| closed ). ", },
adjectives: "desk",
place: { attached: "desk" },
is: { listed_in_parent: false },
});
MyGame.createAsset({
class: "Drawer",
name: "bottom drawer",
synonyms: "bottom desk drawer",
descriptions: { look: "The bottom drawer is $( bottom drawer is| open or| closed ). ", },
adjectives: "desk",
place: { attached: "desk" },
is: { listed_in_parent: false },
});
MyGame.createAsset({
class: "Collection",
name: "desk drawers",
place: { attached: "desk" },
collection: "top drawer, middle drawer, bottom drawer",
synonyms: [ "drawers", "three drawers" ],
is: { listed_in_parent: false },
descriptions: {
look: function()
{
var openCount = [];
var closedCount = [];
var complicatedMsg = "The desk has three drawers stacked vertically. ";
MyGame.$("top drawer").is.closed ?
closedCount.push( "top drawer" ) : openCount.push( "top drawer" );
MyGame.$("middle drawer").is.closed ?
closedCount.push( "middle drawer" ) : openCount.push( "middle drawer" );
MyGame.$("bottom drawer").is.closed ?
closedCount.push( "bottom drawer" ) : openCount.push( "bottom drawer" );
if( 0 === openCount.length )
{
complicatedMsg += "All three are closed.";
}
else if( 0 === closedCount.length )
{
complicatedMsg += "All three are open.";
}
else if ( 2 == openCount.length )
{
complicatedMsg += "The "
+ openCount[ 0 ]
+ " and the "
+ openCount[ 1 ]
+ " are open. The "
+ closedCount[ 0 ]
+ " is closed. ";
}
else if ( 2 == closedCount.length )
{
complicatedMsg += "The "
+ closedCount[ 0 ]
+ " and the "
+ closedCount[ 1 ]
+ " are closed. The "
+ openCount[ 0 ]
+ " is open. ";
}
return complicatedMsg
},
},
});
In the "desk drawers" Collection, take special note of these lines:
name: "desk drawers",
synonyms: [ "drawers", "three drawers" ],
collection: "top drawer, middle drawer, bottom drawer",
place: { attached: "desk" },
is: { listed_in_parent: false },
collection
is set to a list of the items that
the Collection represents. This is important, because some
Verb actions will be forwarded to
the items in the list. In this example, open drawers
will try to open each drawer in turn as if the player had input
open top drawer then open middle drawer
then open bottom drawer
.
name
and synonyms
have been set
to plural words that players are likely to use.place
is set to on desk
,
the same as the drawers, and is.listed_in_parent
is set to desk
so that the Collection doesn't show
up in the Room description.
Created by Ivan Cockrum on Sunday, May 29, 2022.
For more information, please send mail to webmaster@adventurejs.com.