Adventure.js Docs Downloads
Score: 0 Moves: 0

Class: Events

Defined in: adventure/Events.js, line 13

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
IndexMethodsProperties

Methods Collapse all  |  Expand all

Properties Collapse all  |  Expand all

game :Object

Defined in: adventure/Events.js, line 67

Default value: {}

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

Defined in: adventure/Events.js, line 74

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

Defined in: adventure/Events.js, line 81

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

Defined in: adventure/Events.js, line 88

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

Defined in: adventure/Events.js, line 95

Event to be fired on queue next input when parsing a queue.
Documentation generated by JSDoc 3.6.11 on Mon Nov 20 2023 18:01:44 GMT-0800 (Pacific Standard Time)
Found a problem or error in the docs? Report it to docs@adventurejs.com.