-
Notifications
You must be signed in to change notification settings - Fork 14
Using Parameters with the Text Processor
Using parameters is more complicated, but very powerful. If you can get you head around it, there are all sorts of tricks you can use, in particular to make responses that are neutral with respect to the objects involved.
You can send a set of parameters to the msg
function, as a dictionary. The text processor directive can then access these to modify your text.
For the basics of using the text processor, see here.
For more on using these for neutral language, see also here.
A lot of features of Quest 6 use text processor parameters, and it is convenient to pass the same dictionary to other functions too. It is therefore necessary to be consistent with regards to what is in that dictionary.
Name | Comment |
---|---|
char | The character doing the action, usually the player |
item | The item that is being manipulated |
npc | Other character (could be the player) |
obj | Other object |
whole | The object that item is a component of |
multiple | True if this is one of multiple items to be handled in a command |
count | The count for the object, item |
[name]_count | The count for the named object |
Most of these will not be applicable most of the time. Only "char" will be present always, "item" nearly always.
The simplest way to use parameters is just to access them via the show
directive. You can either provide a string, which is used as is; or an object together with an attribute name, to have the attribute inserted.
msg("Here is some {show:my_text}.", {my_text:"interesting text"});
-> Here is some interesting text.
msg("Here is a {show:item:alias}.", {item:w.coin});
-> Here is a gold coin.
// can also be used without parameters!
msg("Here is a {show:coin:alias}.");
-> Here is a gold coin.
If the attribute is a function, it will be run, with the parameters sent as a dictionary, and the value returned - which must be a string - will be inserted.
If the attribute is a Boolean, the string used is determined by lang.tp_true
and lang.tp_false
- "true" and "false" by default.
This rather contrived example is taken from the unit tests:
w.book.func1 = function() { return "test1" }
w.book.func2 = function(options) { return "It is " + options.char.alias + " reading the book." }
msg("Simple text: p2={show:item:func1}", {item:w.book})
msg("Simple text: p2={show:item:func2}", {item:w.book, char:w.Kyle})
->
Simple text: p2=test1
Simple text: p2=It is Kyle reading the book.
If you want to display a number, you might want to look at the number
or ordinal
directives.
Note that show
can also be used to display object values, as discussed here. It will try to match an object in the parameters first, before looking for one in the game world.
Gives the item's alias, followed by a colon, if "multiple" in the params is true. This has a very specific role, and it probably but much use outside of that, but for the role is very use.
If the player does GET ALL, the response for each individual pick-up needs to make clear what item is being processed. There are broadly two approaches; either giving a long phrase that must it clear, such as "You pick up the book." or prefix a short phrase, such as "Book: Taken." Quest 6 tends to do the former, while Quest 5 generally the latter.
If you want to use the latter, then this directive is the answer. This will automatically insert the alias of the item when needed. Here is an example:
lang.take_successful = "{multi}Taken."
Some of the directives already discussed supports params; "show", "money" and the various conditional directives. If the name of the object is actually the name of a parameter, this will be used instead.
msg("{nm:item:the:true} is {$:item}", {item:w.carrot})
To print the name of an object (i.e., what it is called, its alias, rather than the "name" attribute), use the nm
directive. Behind the scenes this uses the getName
function in lang-en.js (so it is language neutral), and you can specify if "the" or "a" should be prepended as required. You can add true
as a further parameter to have it capitalised.
msg("Here is {nm:item:the}.", {item:"Kyle"});
-> Here is Kyle.
msg("Here is {nm:item:the}.", {item:"umbrella"});
-> Here is the umbrella.
If the item has an owner, Quest will indicate that. You can use "THE" and "A" instead of "the" and "a" to stop that.
w.umbrella.owner = "Kyle"
msg("Here is {nm:item:the}.", {item:"umbrella"});
-> Here is Kyle's umbrella.
msg("Here is {nm:item:THE}.", {item:"umbrella"});
-> Here is the umbrella.
To get the possessive form, use nms
. This will append 's
to the name, or replace it with "your" or "my" if appropriate.
msg("It is {nms:char:the} book.", {char:game.player})
-> It is your book.
msg("It is {nms:char:the} book.", {char:w.Kyle})
-> It is Kyle's book.
You can use "the-pa" instead of "the", and "a-pa" instead of "a" to have it use the possessive form. You need to specify whose it is with the fifth parameter. These two examples therefore have two colons together as they do not use the fourth. The first specifies the owner in the directive, the second as a parameter.
"There is {nm:obj:a-pa::Kyle}.", {obj:w.book}
"There is {nm:obj:a-pa::npc}.", {obj:w.book, npc:w.Kyle})
The "list" works similar to "nm", but with a list of things; the list must be in the parameters. Most of the options for "nm" will also work here. Note that this does not work well with COUNTABLEs - it will assume there is exactly one.
"You can see {list:list:a}.", {list:[w.book, w.Kyle]}
-> "You can see a book and Kyle."
The list can include strings as well as objects. Note that "the" or "a" will not be prepended to strings, as Quest will not know when that is appropriate.
"The book, Kyle and the milk jug.", processText("{list:list:the:true}.", {list:[w.book, w.Kyle, 'the milk jug']}
-> "The book, Kyle and the milk jug."
To conjugate a verb, use cj (conjugate; which just gives the correct form of the verb), nv (noun-verb; prepends the name of the object to the verb) or pv (pronoun-verb; prepends the correct pronoun to the verb). Add a third parameter, true
, to capitalise.
// Using the name
msg("{nv:item:be:true} here.", {item:"Kyle");
-> Kyle is here.
msg("{nv:item:be:true} here.", {item:"shoes");
-> Shoes are here.
msg("{nv:item:be:true} here.", {item:game.player);
-> You are here.
// Using the pronoun
msg("{pv:item:be:true} here.", {item:"Kyle");
-> He is here.
msg("{pv:item:be:true} here.", {item:"shoes");
-> They are here.
msg("{pv:item:be:true} here.", {item:game.player);
-> You are here.
These will produce the pronoun for the given item. You can again add "true" as an additional parameter to capitalise.
msg("Kyle is {pa:item} bear.", {item:game.player);
-> Kyle is your bear.
msg("Kyle is {pa:item} bear.", {item:"Lara");
-> Kyle is her bear.
- ob: The object; I, you, he, she, it or they
- sb: The subject; me, you, him, her, it, them
- ps: The possessive; mine, yours, his, hers, its, theirs
- pa: The possessive adjective; my, your, his, her, its, theirs
- rf: The reflexive; myself, yourself, etc.
The "pa2" directive expects to be given two items. It will give the possessive adjective on the first object if they use different pronouns, or the possessive form of the name if they use the same pronouns. If that does not make sense, take a look at the examples, which use the same string, but different characters.
msg("'Please stop!' exclaims {nm:chr1:the} when {nv:chr2:rip} {pa2:chr1:chr2} book to shred.", {chr1:w.Kyle, chr2:game.player});
-> 'Please stop!' exclaims Kyle when you rip his book to shred.
msg("'Please stop!' exclaims {nm:chr1:the} when {nv:chr2:rip} {pa2:chr1:chr2} book to shred.", {chr1:w.Kyle, chr2:w.Boris});
-> 'Please stop!' exclaims Kyle when Boris rips Kyle's book to shred.
In the first, it is clear "his" refers to Kyle, as the other person is you. In the second it could refer to Kyle or Boris, so we want the name to make it clear.
Are similar directives needed for other pronouns? Let me know!
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
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
- 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
- Following an agenda
- Reactions
- Giving
- Followers
- 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!)
- Attributes for characters
- Attacking and guarding
- Skills and Spells
- Limiting Magic
- Effects
- The Attack Object
- 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)
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
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