Pre-release
AdventureJS Docs Downloads Bundler Devlog Score: 0 Moves: 0
Tutorial showing a list of game properties and functions. tutorial, custom code, properties, functions

Public Functions:Game

Properties

These specific game properties provide shortcuts to a few important game objects.

  • MyGame.input Returns the global input object for this turn.
  • MyGame.last_turn Returns the global input object for the last turn.
  • MyGame.player Returns the object of the current player asset.
  • MyGame.room Returns the object of the current room asset.
  • MyGame.score Returns the current game score.

Getters

Game getter functions provide shortcuts to functions scoped to the game object.

  • MyGame.getDirections()   An array of direction names This method returns the current room's exit directions in an array. For example, a returned object might look like this:
    [ "out", "north", "down", "up", "south", "east", "west" ].
  • MyGame.getExits()   Object This method returns the current room's exits as an object with key/value pairs corresponding to the directions of the exits / and the IDs of the exit objects.
    Expand for example

    A returned object might look something like this:

    {
      "out": "standing_room_out",
      "north": "standing_room_north",
      "down": "standing_room_down",
      "up": "standing_room_up",
      "south": "standing_room_south",
      "east": "standing_room_east",
      "west": "standing_room_west"
    }
    To make use of the return you might do something like this function which gets a list of the current room's exits and then prints a statement for each one.
    let exits = MyGame.room.getExits();
    Object.keys(exits).forEach(key => {
      let exit = exits[key];
      let asset = MyGame.getAsset(exit);
      let msg = `You can go ${key} through the ${asset.name}. `;
      MyGame.print( msg );
    });
    
  • MyGame.getInput()   Object Returns the global input object for this turn. This shortcut is available: MyGame.input
  • MyGame.getPlayer()   Object This method returns the object of the current player asset. This shortcut is available: MyGame.player
  • MyGame.getRoom()   Object This method returns the object of the current room asset. This shortcut is available: MyGame.room

Misc

Game functions...

  • MyGame.doStartGame()     This is a special property on the game object that works like a verb action. It's only called if an author defines it. If the author defines it as a function, that function will be called when the game starts. This allows authors to run arbitrary code when the game starts. Use it like this:
    MyGame.doStartGame = function(){
      // author's code here
    }
  • MyGame.isRoom('asset') {String} the name or id of a room asset Boolean This method asks whether the provided string matches the current room, and returns a boolean. Only considers the player's current room; doesn't account for NPCs in other rooms.