-
Notifications
You must be signed in to change notification settings - Fork 17
Dynamic Room Descriptions
As the player moves through your game world, she is going to change it, and your room descriptions should change to reflect that.
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.
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.
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.
Tutorial
- First steps
- Rooms and Exits
- Items
- Templates
- Items and rooms again
- More items
- Locks
- Commands
- Complex mechanisms
- Uploading
QuestJS Basics
- General
- Settings
- Attributes for items
- Attributes for rooms
- Attributes for exits
- Naming Items and Rooms
- Restrictions, Messages and Reactions
- Creating objects on the fly
- String Functions
- Random Functions
- Array/List Functions
- The
respond
function - Other Functions
The Text Processor
Commands
- Introduction
- Basic commands (from the tutorial)
- Complex commands
- Example of creating a command (implementing SHOOT GUN AT HENRY)
- More on commands
- Shortcut for commands
- Modifying existing commands
- Custom parser types
- Note on command results
- Meta-Commands
- Neutral language (including alternatives to "you")
- The parser
- Command matching
- Vari-verbs (for verbs that are almost synonyms)
Templates for Items
- Introduction
- Takeable
- Openable
- Container and surface
- Locks and keys
- Wearable
- Furniture
- Button and Switch
- Readable
- Edible
- Vessel (handling liquids)
- Components
- Countable
- Consultable
- Rope
- Construction
- Backscene (walls, etc.)
- Merchandise (including how to create a shop)
- Shiftable (can be pushed from one room to another)
See also:
- Custom templates (and alternatives)
Handing NPCs
- Introduction
- Attributes
- Allowing the player to give commands
- Conversations
- Simple TALK TO
- SAY
- ASK and TELL
- Dynamic conversations with TALK TO
- TALK and DISCUSS
- Following an agenda
- Reactions
- Giving
- Followers
- Visibility
- Changing the player point-of-view
The User Experience (UI)
The main screen
- Basics
- Printing Text Functions
- Special Text Effects
- Output effects (including pausing)
- Hyperlinks
- User Input
The Side Panes
Multi-media (sounds, images, maps, etc.)
- Images
- Sounds
- Youtube Video (Contribution by KV)
- Adding a map
- Node-based maps
- Image-based maps
- Hex maps
- Adding a playing board
- Roulette!... in a grid
Dialogue boxes
- Character Creation
- Other example dialogs [See also "User Input"]
Other Elements
- Toolbar (status bar across the top)
- Custom UI Elements
Role-playing Games
- Introduction
- Getting started
- Items
- Characters (and Monsters!)
- Spawning Monsters and Items)
- Systema Naturae
- Who, When and How NPCs Attack
- Attributes for characters
- Attacking and guarding
- Communicating monsters
- Skills and Spells
- Limiting Magic
- Effects
- The Attack Object
- [Extra utility functions](https://github.com/ThePix/QuestJS/wiki/RPG-Library-%E2%80%90-Extra Functions)
- Randomly Generated Dungeon
- Quests for Quest
- User Interface
Web Basics
- HTML (the basic elements of a web page)
- CSS (how to style web pages)
- SVG (scalable vector graphics)
- Colours
- JavaScript
- Regular Expressions
How-to
Time
- Events (and Turnscripts)
- Date and Time (including custom calendars)
- Timed Events (i.e., real time, not game time)
Items
- Phone a Friend
- Using the USE verb
- Display Verbs
- Change Listeners
- Ensembles (grouping items)
- How to spit
Locations
- Large, open areas
- Region,s with sky, walls, etc.
- Dynamic Room Descriptions
- Transit system (lifts/elevators, buses, trains, simple vehicles)
- Rooms split into multiple locations
- Create rooms on the fly
- Handling weather
Exits
- Alternative Directions (eg, port and starboard)
- Destinations, Not Directions
Meta
- Customise Help
- Provide hints
- Include Achievements
- Add comments to your code
-
End The Game (
io.finish
)
Meta: About The Whole Game
- Translate from Quest 5
- Authoring Several Games at Once
- Chaining Several Games Together
- Competition Entry
- Walk-throughs
- Unit testing
- Debugging (trouble-shooting)
Releasing Your Game
Reference
- The Language File
- List of settings
- Scope
- The Output Queue
- Security
- Implementation notes (initialisation order, data structures)
- Files
- Code guidelines
- Save/load
- UNDO
- The editor
- The Cloak of Darkness
- Versions
- Quest 6 or QuestJS
- The other Folders
- Choose your own adventure