-
Notifications
You must be signed in to change notification settings - Fork 17
Template ‐ TAKEABLE
Use this template to allow the player to pick something up and drop it. Both use the moveToFrom function to do the work, which will call afterMove(options)
if it exists and the move is successful.
createItem("old_newspaper", TAKEABLE(), {
examine:'A newspaper from the eighties; yellow with age.',
read:'You spend a few minutes reading about what happens on the day 14th June 1987 (or perhaps the day before).',
loc:'basement',
afterMove:function(options) {
if (options.toLoc === game.player.name) msg("Great, now you are carrying an old newspaper...")
},
})
createItem("postit_note", TAKEABLE(), {
alias:'post-it note',
examine:"The sticky yellow note has something written on it; the number 17.",
loc:'office',
scenery:true,
})
NOTE: Several other templates (such as WEARABLE and EDIBLE) include this one, so there is no need to use both.
When an object is moved from a source location to a destination location (in fact any time "moveToFrom" is used):
- the source location's
afterTakeFrom(item)
function is run - the destination location's
afterDropIn(item)
function is run - the item's
afterMove(toLoc, fromLoc)
function is run
The attribute "takeable" will be true
.
The function takeFromLoc(char)
can be used to change when an item is taken from. This can be useful for weird objects, such as ropes, where you need to consider which end of the rope is picked up.
Use "testDrop" and "testTake" to control whether the item can be dropped or picked up in the current situation. Each take a dictionary parameter, which will include "char", the character doing it, and "multiple", a Boolean that will be true
if this is one of several items the player is trying to drop or take. The example shows how the "multiple" value can be used. The function should return true
if the item can be picked up, or give a message saying why and return false
otherwise.
testTake:function(options) {
if (this.nailed_down) {
msg(prefix(this, options) + "It is nailed down!")
return false
}
return true
}
For custom take and drop messages, use "msgTake" and "msgDrop", strings that can use "char" and "item" as text processor parameters. For example:
msgTake:"{nv:char:take:true} {nm:item:the}.",
As an aside, if you have an item that cannot be picked up, but there is a chance the player will try to do so, you can just give the item a "take" attribute.
createItem("old_newspaper", {
examine:'A newspaper from the eighties; yellow with age.',
read:'You spend a few minutes reading about what happens on the day 14th June 1987 (or perhaps the day before).',
loc:'basement',
take:'It seems to be glued down.'
})
This is only relevant to items that are both TAKEABLE and can be more than one location at a time (as is the case for the ROPE and COUNTABLE templates). It is included for completeness, but authors will very rarely have to worry about it.
The standard TAKE and DROP commands use the "moveToFrom" function attribute, which uses the "loc" attribute. Similarly, when working out what a character is carrying, Quest uses an item's "isUltimatelyHeldBy" function attribute. If your item handles its location another way, then you will need a custom "moveToFrom" and "isUltimatelyHeldBy" attributes. This is typically because an item can be in
For "isUltimatelyHeldBy", there is a util.multiIsUltimatelyHeldBy
which handles multiple locations. The COUNTABLE template assembles an array of location names, and passes this to util.multiIsUltimatelyHeldBy
to do the work.
res.isUltimatelyHeldBy = function(obj) {
const locs = []
for (const key in this.countableLocs) {
if (this.countableLocs[key]) locs.push(key)
}
return util.multiIsUltimatelyHeldBy(obj, locs)
},
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