Dynamic Room Descriptions - ThePix/QuestJS GitHub Wiki
As the player moves through your game world, she is going to change it, and your room descriptions should change to reflect that.
Scenery Objects
The simplest example is when the player picks up an item flagged as scenery. And the simplest way to handle that is with a text processor directive that tests the scenery flag. Let us suppose a clock.
"The lounge is very fancy with an impressive fire. On the mantelpiece you can see {if:clock:scenery:a carriage clock and }two silver candlesticks."
When the clock is picked up, the scenery flag is automatically turned off, and so the clock disappears from the room description. If the clock is put down, it will be handled as a normal item, in the list of items here.
Objects that could be anywhere
Suppose the player can open a magic portal; this could be in any room, but obviously needs to be part of the description. How can we handle that without having to modify every room description?
The trick is to modify the room template is settings.js. Here is an example. The new bit is {roomDescExtra}
in the third line.
settings.roomTemplate = [
"#{cap:{hereName}}",
"{terse:{hereDesc}{roomDescExtra}}",
"{objectsHere:You can see {objects} here.}",
"{ifNot:settings:playMode:play:{ifExists:currentLocation:todo:{class:todo:{show:currentLocation:todo}}}}",
]
Now every room description will have the roomDescExtra
directive appended. We just need to create that; it should go in code.js.
tp.addDirective("roomDescExtra", function(arr, params) {
let s = ''
if (w.magic_portal.loc === currentLocation.name) {
s += " There is a magic portal here."
}
return s
})
This can be readily extended to allow for all sorts of changes to your locations.
Global changes
If you want your game to reflect changes across the world, you can change settings.getLocationDescriptionAttName
. By default, Quest uses the locations "desc" attribute to give the description, however the built-in settings.getLocationDescriptionAttName
first checks if game.dark
is true, and if it is tells Quest to use "darkDesc" instead.
You can include your custom version to tell Quest to use different descriptions, depending on the game state. This example checks to see if player.apocalypse
is true. If it is - and the location has the right attribute - it tells Quest to use "apocDesc" for the desciption.
settings.getLocationDescriptionAttName = function() {
return player.apocalypse && currentLocation.apocDesc ? "apocDesc" : "desc"
}
As for a normal "desc" attribute, the "apocDesc" on your locations could be either a string or a function that returns a string, and is optional; it will just use the normal "desc" attribute if there is no "apocDesc".
createRoom("back_room", {
desc:'A large room with straw scattered across the floor. The only exit is west',
apocDesc:'A large room with writhing worms all across the floor, and ichor dropping from the walls. The only exit is west',
west:new Exit('great_hall'),
})
You could have several different alternative descriptions, perhaps reflecting the weather or time of day day or something else. Bear in mind that if you use "darkDesc" you also need to allow for that.