-
Notifications
You must be signed in to change notification settings - Fork 18
Template ‐ COUNTABLE
Often in a text adventure there are several instances of the same thing. Perhaps there are arrows the player can shoot or sticks the player can build with or healing potions the player can use. To track all the instances of one type, Quest 6 uses the COUNTABLE template.
NOTE: If the user does not specify a number, Quest assumes she wants to TAKE all that are there unless there is an infinite number there, in which case only one is taken. However, for DROP just one will be assumed.
NOTE: Do not add the TAKEABLE template to a countable item; that is done automatically.
Behind the scenes, Quest uses some trickery to make one object appear to be any number in several places, so when you create your countable, you just create a single item, but you have to state where it is and in what quantity.
Here is a simple example:
createItem("brick", COUNTABLE({lounge:7, dining_room:1}), {
examine:"A brick is a brick.",
})
Note that the COUNTABLE template needs to be given a list (actually a dictionary) of locations and numbers. This means there is no need to give it a "loc" attribute.
The other complicated bit is the "regex" attribute. Quest uses this attribute to match against alternative names. In this case we want to match "1 BRICK" or "23 BRICKS" or whatever. If you want, you can just replace "bricks" with the plural of your countable item name, and skip the next section.
When the user types a command, the parser will try to match objects using regular expressions, and the "regex" attribute. Quest will set this for you, but it will only work properly if the plural is the singular plus the letter s, as is the case for brick above.
Here is the regex Quest will create for the brick, so we can look in detail:
/^(\d+ )?bricks?$/
The slashes at the start and end just signify that this is a regular expression, just like quote marks fir a string. The ^
and $
match the start and end of a string. This leaves two parts:
(\d+ )?
bricks?
The first part matches numbers - \d
indicates a digit, and \d+ indicates one or more digits. We wrap that in brackets and append a ?
to indicate that it is optional.
The bricks
just matches that word, but the ?
on the end indicates the s
is optional.
You can use the string "infinity" to indicate there is an inexhaustible supply at a location.
There are three functions that facilitate using countables.
countAtLoc(loc)
- Returns the number at the given location.
takeFrom(loc, count)
- Removes the given number from the location.
giveTo(loc, count)
- Adds the given number to the location.
There are extra options for lang.getName
too. Use the item name, followed by "_count" to tell lang.getName
how many it should say. You can use the string "infinity" to indicate an indefinite, but large number. Use "loc" to indicate a room to use the count from. Set "article" to count to have "one" used, rather than the/an.
lang.getName(w.brick, {brick_count:5, capital:true, article:INDEFINITE})
lang.getName(w.brick, {brick_count:'infinity', article:INDEFINITE})
lang.getName(w.brick, {loc:'lounge', article:INDEFINITE})
lang.getName(w.brick, {brick_count:1, capital:true, article:COUNT})
These can also be done with the text processor.
"{nm:item:a:true}", {item:w.brick, brick_count:5}
"{nm:item:a}", {item:w.brick, item_count:'infinity'}
"{nm:item:a}", {item:w.brick, brick_count_loc:'lounge'}
"{nm:item:count:true}", {item:w.brick, brick_count:1}
Here is a full example for leaves, which is made more complicated because of the plural. Note that there are an infinite number of leaves in the woods. If an NPC, Mary, is present the player cannot pick them up.
createItem("leaf", COUNTABLE({woods:'infinity'}), {
regex:/^(\d+ )?(leaf|leaves)?$/,
scenery:true,
pluralAlias:"leaves",
infinity:"lots of",
examine:"There are leaves everywhere. You are in some woods in Autumn, so no surprise.",
testTakeRestrictions:function(options) {
if (w.Mary.isAtLoc("woods")) {
msg("You pick up " + lang.getName({article:DEFINITE, count:options.count}) + ". 'Why do you want a bunch of leaves?' asks Mary.");
msg("'I don't' You quickly drop " + (options.count === 1 ? "it" : "them") + ".");
return false;
}
return true;
},
})
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