Pulp Solution: Adding a Debug Room

I wound up helping out just a little with @intellikat's Heavy Drinker game. One this first things I did was add a debug room, pictured below. This is how I did it.

Obviously, the very first thing to do is create a new room. Debug rooms are not production level end user content, so they generally look ugly like the one in the picture above. Consider cloning an existing map with a lot of space if you prefer. Also, it can make sense to create a few interconnected debug rooms using warps or standard exits if you need them.

The next problem is getting into the debug room, since it cannot be accessed during normal gameplay. The simplest solution is to gate a goto call behind some sort of input that will never be used in your game. For example, Heavy Drinker does not use the Crank, so undocking it jumps the player into the debug room. Alternatively, you could use A+B, or the accelerometer, or something else.

// player event
on undock do
  goto 12,8 in "999_debug_room"

I decided to make docking the crank restore the player to their previous position in the world. This was actually the use case for my Warping Between Alternate Worlds post. The actual robust functionality used starts by setting the initial debug room position in the player's load event. It also has a debug_build variable that can be used to turn off the functionality for production builds.

on load do
  debug_build = 1
  debug_x = 12
  debug_y = 8

The crank code to save and restore position looks like this.

on undock do
  if debug_build==1 then
    resume_x = event.px
    resume_y = event.py
    resume_room = event.room
    goto debug_x,debug_y in "999_debug_room"

on dock do
  if debug_build==1 then
    goto resume_x,resume_y in resume_room

The debug room itself saves the position in it on exit. It also sets the developer friendly room id in the enter event so functionality can be gated by room number.

// 999_debug_room events
on enter do
  room = 999

on exit do
  debug_x = event.px
  debug_y = event.py

The debug room for Heavy Drinker has warp points to each production room in the game. See the end of my post on Calling Events on Walkable World Tiles for information on how to implement warping by interacting with sprites. For a large game, you might only want to have warps to key areas. It also has a bunch of healing items. It would be easy enough to add a sprite to toggle invincibility mode, lower health, reset some internal values, or do anything else that is useful for testing your game. That is what the debug room is for!

Finally, debug rooms are used to make testing easier. For example, invincibility is useful when testing game flow, so you do not die while focusing on other gameplay details. Having said that, debug rooms are not intended to be release quality, so they can mess up the internal state of a game. You may have bugs that only manifest when using your debug room- they are safe to ignore for final release. WARNING: Do not use your debug room for final testing!

1 Like