Console Debugging
Debugging · Use console.log to track game state, variables, method calls.
Console Debugging
What it is
console.log(), console.warn(), console.error(), and console.table() print messages and values to the browser’s developer console. Logs can include any JavaScript value — objects, arrays, even DOM nodes — and the console renders them interactively.
Why it matters
This is the fastest way to see what your code is doing without pausing it. When a value seems wrong, a console.log at the right place can reveal the bug in seconds.
How GateGame implements it
During development I sprinkled console.log("Initializing GameLevelMazeSub...") calls to confirm level-load timing. NPC interact() methods log when they fire to verify the proximity check is working. Logging is guarded behind a debug flag so production builds stay quiet.
Code Example
console.log("Initializing GameLevelMazeSub...");
console.log("player pos", this.player.x, this.player.y);
// Guarded so production stays quiet
if (gameEnv.debug) {
console.log('collision', other.constructor.name, direction);
}
Key Takeaway
Log generously during dev, guard it behind a flag for production. A well-placed
console.logis faster than any debugger.