-
Notifications
You must be signed in to change notification settings - Fork 17
Change listeners
Quest 5 has change listeners, and they are very useful in some situations. My view is that they are not needed in Quest 6 because you can readily return values from functions. But if you want to use a change listener, the capability is there.
You need to register change listeners. This adds them to a list, and at the end of each turn Quest will go through that list, before turn events are run, and again after they are run, and also after any timer events are run. Be aware that if a change listener itself changes a value that is being watched, when that change gets noticed will depend on where in the list the listener is.
Use util.addChangeListener
to add a listener. This must be done before the game starts; you cannot add new listeners once the game is running due to how games are saved. The function takes three parameters, the object, the name of the attribute to watch and the function to fire when it changes.
The simple example just gives a message when the attribute changes.
util.addChangeListener(w.book, "watchedStringAttribute", function(o, current, previous) {
msg("watchedStringAttribute changed from " + previous + " to " + current)
})
The triggered function takes four parameters; the object, the new value, the old value and the attribute name. Only the first three are used in the example.
You can add a fourth parameter to util.addChangeListener
to give a custom test. This means your function could fire is different situations, for example, when an attribute falls below zero, as illustrated below. This resets the attribute to zero, ensure if effectively never goes negative, but it could be used to note the monsters is dead, for example.
util.addChangeListener(w.book, "watchedNumberAttribute", function(o, current, previous, att) {
o[att] = 0
}, function(o, current, previous) {
return current < 0
})
Because of how games are saved, you are limited to only watching number attributes and string attributes. Furthermore, because Quest guesses which is which when a game loads, and an attribute that is a string of digits will be taken as a number when a game is loaded, and will wrongly trigger a change, so is to be avoided.
If there is any chance that you will extend your game after you have released it (say adding a new region players can explore), I would advise putting the code that sets all your change listeners together. When you extend your game, add any new listeners after the others and you will hopefully find players can load games saved in the old version into the new version (but do test that!).
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