Debugging your code

Every Javascript application requires debugging and any game developed using kheljs is no exception. The first step in debugging is to use traditional debugging tools on browser devtools such as chrome devtools. These devtools allow you to set a breakpoint in your code and step over your code as they are executed by the Javascript engine.

While in development mode, kheljs makes a lot of data structures in the game accessible as global variables. For example, you can access the following variables from Javascript console to inspect the content of various data structures in the game.

  • player - The player object that contains player configuration and assets loaded for the player character.
  • levelInventory - the set of inventory items for the level
  • playerInventory - the set of inventory items acquired by the player
  • terrainItems - the list of items created for the terrain.
  • activeItem - the item acquired by the player and which is currectly marked as active.

Using these variables from Javascript console, you can inspect a lot of information about the game without debugging or pausing the Javascript engine. For example, you can get the current position of the player character by evaluating the following expression:


Or list the set of items in the level inventory i.e. the list of items player can pick up from that level:


Or see the details of the first item in the player's inventory


and so on.