-
Notifications
You must be signed in to change notification settings - Fork 17
An Encyclopedia
If your game is set in some other world, you might want to give the player access to an encyclopedia, so the user can look up places, people, etc. that form the backdrop to the universe. This works best in a sci-fi setting, where the player might have access to Space-Google on her space phone.
This is adapted from a similar system. It should work but if you run into problems, let me know.
A big issue is the hassle of typing all the entries, so a major concern when designing this system is make that as easy as possible. We will start, then, by creating a few entries.
const encyclopedia = {
"SS Star Quest":"The SS Star Quest is an {i:Intrepid} class warship, launched {time:-195341} from Newport, in Mars orbit.",
"The Admiralty":"The Space Admiralty, or more often just the Admiralty, is the administration for Earth-based space military.",
"Stardate":"The \"Stardate\" has been adopted as a universal time system across [[Union]] space.",
"Alliance":"Currently thirty four species spread across 3962 planets make up the alliance. Its aim is to promote peace and prosperity throughout the galaxy. The latest species to join the Alliance was the [[Chal]], five years ago.",
"Terran Union of Planets":"Of the 84 planets that are considered to be terran (earth and its colonies), 68 are part of the Terran Union of Planets.|The Terran Union of Planets is a subset of the [[Alliance]].",
}
Each entry is a name-value pair in a dictionary. Usually I would restrict the names in a dictionary to just letters, numbers and underscores as that allows you to access them using the dot notation and you do not need quote marks, but JavaScript will actually allow any string if you do use quotes, which is great for us here.
Note that we can use the text processor in the value part. Paragraph breaks are denoted by vertical bars. Also, links to other entries are flagged using double square brackets.
Actually, we have two commands; one is used when the player follows a link.
commands.unshift(new Cmd("LookUp", {
regex:/(?:look up|search for|search|google) (.+)$/,
objects:[
{special:'text'},
],
script:function(objects) {
log(objects[0])
w.phone.askDiag(objects[0])
return world.SUCCESS
},
}))
commands.unshift(new Cmd("EncyclopediaLink", {
regex:/encyclopedia-link (.+)$/,
objects:[
{special:'text'},
],
script:function(objects) {
log(objects[0])
w.phone.askDiag(objects[0], true)
return world.SUCCESS
},
}))
All the commands do is pass the search text to w.phone.askDiag
, so we next need to set up the phone.
You need a couple of functions to do the work, and these are probably best put on an item. I have assumed this is on an item called "phone"; adjust accordingly. There is also a "verbsHeld" attribute set.
verbsHeld:['Search from'],
askDiag:function(s, fromLink) {
if (s.length === 0) return
if (s.length < 3) {
msg("On your phone you search for \"" + s + "\", but get over a billion hits. Perhaps search for something a few more characters long?")
return
}
const regex = RegExp(s, 'i')
for (const key in encyclopedia) {
if (regex.test(key)) {
if (!fromLink) msg("On your PAGE you search for \"" + s + "\".")
let strs = []
const paras = encyclopedia[key].split('|')
let flag = true
for (const s of paras) {
if (flag) {
strs.push("<b>" + key + "</b> " + w.phone.expandRefs(s))
flag = false
}
else {
strs.push(w.phone.expandRefs(s))
}
}
msgDiv(strs, {}, 'encyclopedia')
return true
}
}
if (fromLink) {
msg("The link seems to be broken; you wonder if you should report it to someone....")
}
else {
msg("On your phone you search for \"" + s + "\", but find nothing of interest.")
}
return false
},
expandRefs:function(s) {
let match = s.match(/\[\[(.+)\]\]/)
while (match) {
log(match)
const link = '<span onclick="runCmd(\'encyclopedia ' + match[1] + '\')" class="encycLink">' + match[1] + '</span>'
log(match[0])
log(link)
s = s.replace(match[0], link)
log(s)
match = s.match(/\[\[.+\]\]/)
}
return s
},
If the phone (or whatever) can be used via the side pane, you need a text input box to appear. For that to work you need a third command
commands.unshift(new Cmd("LookUpOnPhone", {
regex:/search from phone$/,
objects:[
],
script:function(objects) {
askDiag("Search the web", w.phone.askDiag, "Submit")
return world.SUCCESS
},
}))
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