Adventure.js Docs Downloads
Score: 0 Moves: 0

Don't Panic

We assume that you already know what a text adventure game is and how to play one. (If you don't, here's a basic primer).


Your game needs four files.

Four, count'em, four!

Icon for index.html index.html An HTML wrapper
Icon for Adventure.js adventure.js The Adventure.js
Icon for Adventurejs.css adventurejs.css The Adventure.js
Icon for MyGame.js MyGame.js Your game code

Download them here


Your index file will look like this.

If you downloaded the sample index, it looks exactly like this.

 My Game
<!DOCTYPE html>
<html lang="en">
    <title>"My Game"</title>
    <meta charset="utf-8">
    <link href="css/adventurejs.css" rel="stylesheet" type="text/css">
    <div id="MyGameDisplay" class="game_display"></div>
    <script src="js/adventure.js"></script>
    <script src="js/MyGame.js"></script>
    <!-- You may want to break your game into multiple files. -->
    <!-- Just load them all here! -->
      window.addEventListener('DOMContentLoaded', (event) => {;

Your game code will look like this.

But probably longer. Much, much, longer.
You may find it useful to organize it into multiple files.

First, set up the game.

// MyGame.js
var MyGame = new adventurejs.Game( "MyGame", "MyGameDisplay" )
  title: "Dungeon!",
  author: "Ivan Cockrum",
  description: "Welcome... to the dungeon!",
  version: "0.0.1",
  if_parser_has_no_response_print_this: "I have no response to your input. ",
  if_input_is_empty_print_this: "I didn't see any input. ",
  //print_debug_messages: true,
  if_input_is_empty_print_room_description: false,
  if_input_is_an_asset_name_examine_it: true,

Next, create a room.

  class: "Room",
  name: "Inner Sanctum",
  description: "It feels like days since you entered The Dungeon. You've sprung all the traps, won all the battles, answered all the riddles, retrieved your items from the thief, and finally arrived here, at the inner sanctum. After years of questing, $(our) goal is finally within reach. You clench your fist around the melted brass key that hangs by a fine chain around your neck. ",

Add a player character.

  class: "Player",
  name: "Swordy McSwordface",
  is: { active: true, },
  place: { in: "Inner Sanctum" },

And now, add some objects.

  class: "Key",
  name: "melted brass key",
  is: { indirect_object_of_verb: { unlock: { with_assets: ['battered chest'], }, }, },
  description: "It's a small key, made of brass. It's scarred and a bit melted from some unknown incident, but the teeth appear intact. You've carried it since it was given to you by your father. ",
  article: "a",
  adjectives: [ "brass", "melted", "small" ],
  synonyms: [ "chain" ],
  place: { in: "Swordy McSwordface" },
  is: { known: true, },
  class: "Chest",
  name: "battered chest",
  place: { in: "Inner Sanctum" },
  is: { closed: true, locked: true },
  is: { 
    direct_object_of_verb: { 
      lock: with_assets:[ "melted brass key" ],
      unlock: with_assets:[ "melted brass key" ],
  description: "The battered chest appears to be made of fire hardened teak or walnut bound with straps of dark, tarnished brass. ",
  adjectives: [ "treasure", "wood", "brass", "dark", "tarnished", "teak", "walnut" ],
  synonyms: [ "lock" ],
      doAfterSuccess: function()
        if( MyGame.$("glowing chalice").isIn("battered chest") )
          MyGame.print( "The chalice glows warmly inside the chest, drawing you to it. If half of the legends are true..." );
  class: "Chalice",
  name: "glowing chalice",
  place: { in: "battered chest" },
  description: "The chalice glows enticingly, continuously shifting color across the visible spectrum. You've never wanted anything so much in your life. ",
  contains: "godsmead",
  verb_hooks: {
      doBeforeTry: function()
        if( MyGame.$("glowing chalice").$is("in", "battered chest") )
          MyGame.prependToOutput( "Your hand trembles as you reach for the chalice. " );
      doAfterSuccess: function()
        MyGame.print( "Something unseen rumbles deep beneath the earth. " );
}); // chalice
  class: "Liquid",
  name: "godsmead",
  description: "The godsmead shimmers like liquid gold. ",
}); // godsmead

And that's it!

Ok, there are a few more things to know.
But this basic setup is all you need to get started.

Where to dig in next? We recommend jumping into How to Create a Game of course. You might also browse through Verbs and Assets in the menu to get a sense of the built-in features that are available for you to use in authoring your game. Adventure.js has over 100 pre-written verbs with complete logic for handling any kind of assets.

Documentation generated by JSDoc 3.6.11 on Mon Nov 20 2023 18:01:04 GMT-0800 (Pacific Standard Time)
Found a problem or error in the docs? Report it to