-
Notifications
You must be signed in to change notification settings - Fork 17
Dialog examples
Not sure how useful this is, but I have it, so it might as well be available.
The situation here is that we want to present the player with a large number of options in table. For example, the player is selecting a dress, and can have any combination of style and colour; or the player is picking a tattoo and can pick a design and location. In either case, one set of option is listed across the top (colours or locations) and another listed down the left (style or design). The player clicks a button in the middle of the table with the desired combination.
Here is the code, which is probably best in code.js
let diagTableFunction = false
const tableDiagSelect = function(col, row) {
const diag = document.getElementById("dialog")
diag.style.display = 'none'
diagTableFunction(col, row)
diagTableFunction = false
}
const table = function(title, cols, rows, fn) {
if (test.testing || settings.walkthroughMenuResponses.length > 0) {
fn(cols[1], typeof row === 'string' ? rows[1] : rows[1].name)
return
}
diagTableFunction = fn
const diag = document.getElementById("dialog")
let html = '<h4>' + title + '</h4><br/>'
html += '<table id="diag-table">'
for (let i = 0; i <= cols.length; i++) html += '<colgroup></colgroup>'
html += '<thead><tr><th></th>'
for (const col of cols) {
html += '<th>' + col + '</th>'
}
html += '</tr></thead><tbody>'
for (const row of rows) {
const name = typeof row === 'string' ? row : row.name
html += '<tr><th'
if (typeof row !== 'string') {
html += ' title="' + row.text + '"'
}
html += '>' + name + '</th>'
for (const col of cols) {
html += '<td><input type="button" value="Select" class="diag-table-button" style="color:grey" onclick="tableDiagSelect(\'' + name + '\', \'' + col + '\')"/></td>'
}
html += '</tr>'
}
html += "</tbody></table>"
html += '<p><input type="button" value="Cancel" class="diag-table-button" style="color:grey;float: right;" onclick="tableDiagSelect()"/></p>'
diag.innerHTML = html
diag.style.width = 80 * (cols.length + 2) + 'px'
diag.style.height = 'auto'
diag.style.top = '80px'
diag.style.position = 'fixed'
diag.title = title
diag.style.display = 'block'
}
So how do you use it? Here is an example. You need two arrays, one for the columns, one for the rows. Pass them to the function table
, together with a title and a call-back function. In this case the function just reports back what was selected.
const designs = ['Lion', 'Tiger', 'Dragon', 'Snake', 'AK47', 'Sunset', 'Rose', 'Dagger', 'Mongoose', 'Fire']
const locations = ['Left arm', 'Right arm']
table("Select a Tattoo", locations, designs, function(col, row) {
log('Tattoo selected: ' + col + ', ' + row)
})
A slightly different version, this uses an arrays of dictionaries for the rows (not an option for the columns). The text attribute is then used as a tooltip.
const designs = [
{ name:'Short',text:'A rather short dress'},
{ name:'Long',text:'A long flowing glow, with a tight waist and open back.'},
]
const colours = ['Black', 'White', 'Blue', 'Red', 'Green', 'Yellow', 'Purple', 'Plaid', 'Paisley', 'Tartan']
table("Select a Dress", colours, designs, function(col, row) {
log('Dress selected: ' + col + ', ' + row)
})
If you try these out you will see one table is wide and short, the other tall and thin - it has sized it for you. This does rely on short names for your columns and rows. Note that the player can click the cancel button at the bottomtop right to dismiss the dialog without making a selection; the call-back function is still called, but with no parameters, so your function needs to check for that.
Dialogs are a pain in the neck if you are using unit tests or walk-throughs, as you need a way to by-pass them. Ideally we would have a way to select a certain option, but it is far easier to just say we will pick the same one every time - let us say the second row and second column.
Just add these four lines of code after the function declaration (which is also included).
const table = function(title, cols, rows, fn) {
if (test.testing || settings.walkthroughMenuResponses.length > 0) {
fn(cols[1], typeof row === 'string' ? rows[1] : rows[1].name)
return
}
Now your unit-test or walk-through will automatically make a selection, without showing the dialog.
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