-
Notifications
You must be signed in to change notification settings - Fork 17
Other Functions
Run this function to end the game. The side pane will be be removed (if used), and replaced by vertical text saying "Game over". The text input will also be disabled. You will probably want to add your own text to make clear the game is over. For example (
is an HTML code for a hard space):
msg("You stand on the giant spider's corpse and raise your fist into the air, triumphant!")
blankLine()
msg("T H E E N D", {}, 'centred')
io.finish()
If transcript recording is turned on, a message will be given, with a link that can be clicked to show the transcript.
You can pass true
to the function, and then Quest will give the player the opportunity to click links to UNDO or RESTART. This is especially useful if the player has just died!
Prints a message saying the NPC is moving via the given exit. If the player is in the room the exit starts from, it will say the NPC is leaving that room, if the player is in the room it goes to, the message will say the NPC is entering the room.
If the NPC is going either to or from with a "visibleFrom" attribute, and this list of strings includes the name of the room the player is in, the message will be given, with the original room's "visibleFromPrefix" prepended. This means the movements of an NPC can be observed from different locations. This example has a window; when the player is in the dining room, she will see NPCs going into and leaving the garden.
createRoom("garden", {
desc:"Very overgrown. The garden opens onto a road to the west, whilst the conservatory is east. There is a hook on the wall.",
east:new Exit("conservatory"),
visibleFrom:["dining_room"],
visibleFromPrefix:"Through the window you can see",
})
If you want something to just happen once, you can use this function together with if
:
if (doOnce(obj)) obj.singleTimeFunction()
Behind the scenes, the function will add an attribute to the object and return true
the first time it is called for that object. Subsequent calls will find the attribute is there, and return false
. This ensures the function is only every run once for that object.
That is fine if there is just one such function for a particular object. If you have several, you will need to provide names for the flags, to ensure each is handled separately.
if (doOnce(obj, 'myCustomFlag')) obj.singleTimeFunction()
Sends the given thing to the console. This is just a shortcut for console.log
; it can be sent a string, a number, an array, an object, whatever.
You can use this to run a command as though it was typed by the user. It will get echoed to the screen, and then sent to parser.parse
.
This function is designed to be used within a command. It is common for a command to relate to an item, and to access an attribute of that item, which might be a string or a function. For examine, the TAKE command accesses the "take" attribute of the item.
With this in mind, then, the function has these parameters:
- char: the character doing the command; usually the player, but the player might ask an NPC to take the hat, for example
- item: the item, obviously
- attName: the name of the attribute
- options: an optional dictionary of further parameters (the function will set "char" to the character and "item" to the item unless these are already set)
If the attribute is a string, the string is printed, using options as text processor parameters. If the attribute is a function, the function is called, using options as the only parameter.
NOTE: If you know the attribute is a function, it is probably better to just call the function yourself.
item.attName()
item.attName(options)
Will get the named object. If the name variable is actually an object itself, just returns the object. f the object is not found, or has no "name" attribute an exception is thrown.
This is useful for functions that could be sent an object or the name of an object.
Returns the given number, num, but restricted to lie between min and max; i.e., if number is less than min, then min will be returned instead.
Returns a list of reachable items.
Returns a list of items at the current location and not scenery (i.e., listed if the user types LOOK).
Returns a list of items held (or worn) by the NPC.
Returns a list of NPCs who are here. The former excludes those flagged as scenery, the latter does not.
The getObs
function gets an array of objects (items and rooms) for which the given function returns true
. This simple example gets a list of items for which the "candidate" attribute is true (or indeed any non-falsy value).
const candidates = scopeBy(function(o) {
return o.candidate
})
JavaScript has a shorthand that is useful for simple functions. This example is exactly the same as the above:
const candidates = scopeBy(o => o.candidate)
Use "getContents()" on a container to get a list of items in it.
const contents = w.chest.getContents()
For an NPC or the player you can use "getHolding()", "getWearing()" and "getCarrying()".
const inHerHands = w.Lara.getHolding()
const yourClothes = player.getWearing()
const listAll = w.orc_boss.getCarrying()
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