Adventure Games and Interactive Fiction

Debugging Games in the Browser

by Gamefic on April 1, 2017

Since I started using VS Code for most of my development, I've been eager for the ability to run Gamefic stories in a debugger. The Ruby extension makes debugging relatively easy for most Ruby programs. The challenging part was running a debugger against browser-based versions of games. Thanks to a new feature I've added to the SDK, now there's a solution.

The gfk server subcommand starts a local web server and uses the game's HTML assets the same way a standalone web game would. The major difference is that instead of compiling the game code to JavaScript and running it in the browser, the engine uses AJAX to execute the Ruby code directly from source. VS Code can run the game in a debugger with the following configuration in launch.json:

            "name": "Debug Game",
            "type": "Ruby",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "program": "gfk",
            "args": [
            "showDebuggerOutput": true

The --browser argument automatically opens the game in a browser window after the server starts.

Now you can use the debug features like breakpoints and variable info to troubleshoot your code. If you make any changes, you can reload the page without needing to restart the debugger.

The gfk server subcommand will be included in an upcoming version of the gamefic-sdk gem.