Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0

Class: Events

Defined in: adventure/Events.js, line 12

We only fire a few events, all at the beginning and end of a turn: inputEnter, inputParseBegin, inputParseComplete, and inputQueueNext (which fires between queued inputs). Authors can hook into these to run custom code. For example, you could write a series of random in-game background events tied to specific Rooms, to print additional text to the Display after parsing has completed.

Example:

MyGame.reactor.addEventListener('inputParseComplete', function()
{
  var random = Math.random() * 100;
  switch (MyGame.world._currentRoom.name)
  {
    case "Frigid Wastes":
      if( random < 10 )
      {
        MyGame.print(
          "You're struck by a flash of blinding light as
          sunlight reflects off the packed ice.", "random"
        );
      }
      break;
    case "Desert Wastes":
      if( random > 5 && random < 10 )
      {
        MyGame.print(
          "Heat haze shimmers off the distant dunes.", "random"
        );
      }
      else if( random > 10 && random <  15 )
      {
        MyGame.print(
          "You feel the sand shift beneath your feet.", "random"
        );
      }
      break;
  }
});

Private Constructor:

var foo = new adventurejs.Events(game)

Parameters:

  • game Game
    A reference to the game instance.
Inherited Overrides

Methods Collapse all  |  Expand all

Properties  | 

game :Object

Defined in: adventure/Events.js, line 66

Default value: {}

A reference back to the main Game object.
inputEnter :Event

Defined in: adventure/Events.js, line 73

Event to be fired on player enters input.
inputParseBegin :Event

Defined in: adventure/Events.js, line 80

Event to be fired on input parse begin.
inputParseComplete :Event

Defined in: adventure/Events.js, line 87

Event to be fired on input parse complete.
inputQueueNext :Event

Defined in: adventure/Events.js, line 94

Event to be fired on queue next input when parsing a queue.