-
Notifications
You must be signed in to change notification settings - Fork 14
Supporting USE
The USE command is a bit of an odd one being so generic. The player might try it to do anything, and it does not really have an obvious place in the documentation.
It has broadly two forms:
USE object
USE object1 WITH/ON object2
You can just give the item a "use" attribute; either a string or a function that will be sent a dictionary with the keys "char" and "item", and should return true
or false
.
use:function(options) {
msg("{nv:char:cannot:true} work out how to use it.", options)
return false
},
Alternatively, you can tell Quest to use another command by giving it a "useDefaultsTo" attribute, a function that will be sent the character doing it, and should return a string, the name of the command to use. This example is from the WEARABLE template (and "useDefaultsTo" is really designed for templates); if the character is the player, we want USE to default to the "Wear" command,
useDefaultsTo:function(char) {
return char === player ? 'Wear' : 'NpcWear'
},
When there are two objects involved, it obviously gets more complicated. For one thing, we have to decide who is going to take responsibility.
If the first object has a "useWith" attribute, it gets the responsibility. If not, Quest will look at whether the second object has a "withUse" attribute, and if so, it will go with that.
If both of them fail, it will look at "useWithDefaultsTo" and "withUseDefaultsTo", which work analogousky to "useDefaultsTo" discussed before.
Both "useWith" and "withUse" must be functions, taking two parameters, the character and the other object, and should return true
or false
.
This example is for a key that be be used for winding something up - anything with a "dowindup" attribute in fact.
useWith:function(char, obj) {
if (obj.dowindup) {
return obj.dowindup()
}
else {
return falsemsg("Mandy wonders what she could use the clock key for. Besides winding up the clock, that is.")
}
},
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