Advanced Descriptions:Descriptions
In the
Customize Output: Description
page, we showed the asset.description property. In fact,
asset.description is actually a shortcut to
asset.descriptions.look, which is the default description when a
player looks at or examines a tangible asset; while
asset.descriptions can contain a whole plethora of other
descriptions to describe the asset in response to other verbs and situations.
All description properties are subject to
StringArrayFunction,
meaning that they can be set to a string, or an array of strings, or a
function that returns a string. All of them are optional and you're not
obliged to use any of them. asset.descriptions.look aka
asset.description will always be returned when no specialized
description is present.
MyGame.createAsset({
class: "Thing",
name: "thing with all the descriptions",
descriptions:
{
// asset.descriptions.look is the default description;
// equivalent to setting asset.description
look: `The thing with all the descriptions has a lot of descriptions. `,
// Returned if player has set descriptions to brief.
brief: `A thing with all the descriptions. `,
// Returned if player inputs "carefully examine thing".
carefully: `Among all the descriptions you notice one specific description. `,
// Descriptions for these aspects will be returned
// if player tries, for example, "look behind thing"
// If that aspect has contents, the contents will be
// listed after the description.
behind: `Behind the thing are some other things. `,
in: `Inside the thing are some other things. `,
on: `On the thing are some other things. `,
under: `Under the thing are some other things. `,
// Returned if player tries to look over thing.
over: `Over the thing with all the descriptions floats another description. `,
// Returned if player tries to look through thing.
through: `Through the thing with all the descriptions, you see another description. `,
// Returned if asset has been destroyed and player
// tries to refer to it.
destroyed: `You can't recall what became of the thing with all the descriptions. `,
// Returned if object can be opened but is closed.
closed: `It looks like the thing is closed. `,
// Returned if object can be closed but is open.
open: `It looks like the thing is open. `,
// Returned if player tried to feel this thing.
feel: `You don't feel anything special about the thing with all the descriptions. `,
// Returned if player tried to listen to this thing.
listen: `You don't hear anything special coming from the thing with all the descriptions. `,
// Returned if player tried to smell this thing.
smell: `The thing with all the descriptions doesn't have any particular odor. `,
// Returned if player tried to smell this thing.
taste: `The thing with all the descriptions doesn't taste of anything much. `,
// If asset is an exit, this will be printed as the
// exit's description in a list of room exits.
listing: `The path west will take you back to the beach. `,
// If asset is a room, this will be printed instead
// of the standard list of exits.
exits: `You can go anywhere and everywhere from here. `,
}
});
All of the descriptions listed above are standardized. If you add your own
arbitrary descriptions, for instance asset.descriptions.foo,
those won't be called unless you call them yourself.
Dynamic Descriptions
All descriptions are subject to StringArrayFunction rules, meaning they can be a string, or an array of strings which will be cycled through, or a function that returns a string.
In this example, we show a gem that returns a random array item when looked at.
MyGame.createAsset({
class: "Gem",
name: "rainbow gem",
descriptions: {
look: {
randomize: true,
array: [
"The gem explodes with brilliant red light. ",
"The gem pulses a deep orange hue. ",
"The gem flashes a bright yellow color. ",
"The gem humbs with a soothing green inner light. ",
"The gem reveals cool blue depths on closer examination. ",
"The gem vibrates with indigo highlights. ",
"The gem shimmers with ultra violet light. ",
],
},
},
});
In this example, we assign a Javascript function to the gem's look description, that randomly chooses a color from a list.
MyGame.createAsset({
class: "Gem",
name: "rainbow gem",
descriptions: {
look: function(){
const colors = [
"red",
"orange",
"yellow",
"green",
"blue",
"indigo",
"violet",
];
const random_color = colors[Math.floor(Math.random() * colors.length)];
const msg = "The gem shimmers with a deep ${random_color} hue. ";
return msg;
},
},
});
We can run any amount of arbitrary code in a desription function. In this example, we attach an ad hoc Javascript function to a computer's look description that checks to see whether a file has been created on the computer.
MyGame.createAsset({
class: "Computer",
name: "computer",
descriptions: {
look: function () {
let msg =
"It's a honking big old desktop computer. It is currently {computer [is] plugged in [or] unplugged}. ";
// get the file asset
let file = MyGame.$("file");
if (file.is.created && file.$is("on", "computer")) {
msg += `The desktop shows a single file. `;
}
return msg;
},
},
});
MyGame.createAsset({
class: "Thing",
name: "file",
descriptions: { look: "A single file sits on the computer's desktop. " },
});