-
Notifications
You must be signed in to change notification settings - Fork 17
The Text Processor
The text processor allows authors to put codes in text that will get translated by Quest, according to the directive given and the conditions when it is printed.
To use the text processor, you can simply add a directive in curly braces in any text that gets displayed. In this simple example, a room description is set to say that room smells only the first time the text is printed:
This is a small dungeon.{once: There is a bad smell in here.}
------------------------------------
^^^^
The text processor takes the entire underlined section. The directive here is "once". Note that it is followed by a colon. Some directives take several parts; these will always be split up with colons. In this case there is just the one extra part. If this is the first time the message is show, that will be added to the text. Otherwise it will not.
The basic text processor is very similar to Quest 5, and nearly all Quest 5 text will work without change, the only exception being the "eval" directive, and its short cut using the equals sign. In fact the example above is identical to the one in the Quest 5 documentation. However, there are a lot more options available is Quest 6!
The Quest 6 text processor introduces parameters. That is, when you print a string, you can also pass along a set of parameters and the text processor will use them to decide what should be printed.
This is used to a huge extent in all the built in messages. For example, when the player takes an item:
"{nv:char:take:true} {nm:item:the}."
The first directive says I want a noun-verb, using the object "char", and the verb "take", capitalised. The second says I want the name of the object "item", with the definite article. This same text can be used for some thugs getting a football, for you getting Mike the Micro-robot or for Lara taking some trousers.
The msg
function automatically uses the text processor, but sometimes you want to invoke it without msg
. Use the processText function.
const s = processText("{nv:char:take:true} {nm:item:the}.", {char:player, item:w.Mike})
When using the msg
function (and related functions), you can use a vertical bar, |
, to tell Quest to start a new line. The text processor is then used with each line. What this means is that text processor directives cannot straddle line breaks.
In the first examples below the directive stops before the line break, and then starts again after it; this is the right way to do it. In the second line, the directive continues right across the line break - it will not work properly.
"Here is my first line with {i:italics.}|{Still italics} on second line."
"Here is my first line with {i:italics.|Still italics} on second line."
Note that the processText
function will not convert vertical bars to new lines.
The msg
function automatically uses the text processor, if you want to not use it, use the rawPrint
function.
If you want to use the text processor, but want the special characters in you text, there are escape codes you can put in the text, which the text processor will ignore, but the msg
command will convert to the character when printing to screen.
Character | Code |
---|---|
{ | @@@lcurly@@@ |
} | @@@rcurly@@@ |
: | @@@colon@@@ |
] | @@@rsquare@@@ |
[ | @@@lsquare@@@ |
JavaScript has its own equivalent of the text processor, and there are times you may find it easier to use that. To use string interpolation, you have to use backticks to surround your string, rather than single or double quotes. You can then put your JavaScript expression inside curly braces with a dollar sign at the start.
These two are the same:
"The answer is " + myValue + "."
`The answer is ${myValue).`
You can mix both types. In this example, the description only includes the clock if the clock's display attribute is equal to the DSPY_SCENERY. We need to insert that value into the text processor command.
createRoom("kitchen", {
desc:`A clean room{if:clock:display:${DSPY_SCENERY}:, a clock hanging on the wall}.`,
...
The clock is scenery until picked up. At that point it stops being part of the room description.
Note that JavaScript string interpolation will happen when the string is created; the text processor does its magic when the string is displayed. We need to use the text processor in that last example because the string is created at the start of the game, and we need it to change depending on the game state at the time it is used. DSPY_SCENERY
, however, is a constant, so we can safely have that set in stone when the game starts.
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