How I do (not) debug my games

I’m writing this because I thought it might be interesting to other programmers. I used this method for about ten years, so it’s pretty sound.

I don’t use debugger. Well, I start it sometimes in (mostly futile) hope of getting a better exception stack trace. Or to look at the generated machine code in disassembly when optimizing. Otherwise, I find it mostly useless.

I don’t use “debug” build. I always build “release” with debug information. So I’m testing the same code people will use to play the game. Debug info is for getting stack info on exceptions and in some other cases.

When I encounter an error (crash, wrong logic, glitches or whatever) I follow these steps:

  • Thinking
  • Reviewing
  • Logging
  • Debugging (or, rather, taking a break)

Each step’s purpose is to get some new info about the problem. If I get new info, I go back to the first step – thinking.
As you see, debugging is actually there, but I rarely get to it. Let’s look at the steps in more detail.

Thinking

Stop and think: what can cause this problem? Is it the result of the code I just wrote/changed? What did I do to cause it? Or was it there before? What subsystems is it limited to? When does it happen, in what conditions? And so on.
Just thinking about the problem often gives some new insights about what can cause it. When you do small incremental changes (and I try to work that way when possible), the changed code is small and easy to grasp with you mind, and the problem is likely there.

Reviewing

Look at your code. Review it. Do you remember it correctly? What is actually written there? (Strange things can happen, especially if you use copy/paste/modify a lot).
Look for things you didn’t think about. Look for things that differ from what you expect them to be. If you use third-party library/engine/whatever, look at the documentation for the things you use to make sure they do what you thing they do, and accept those arguments etc.

If you find something, go back to thinking.

Logging

The code is complex. It can produce emergent results (that’s why you use it in the game, right?) So you might need to look at some values it actually produces. That’s where logging comes in.

Logging is the code that writes some text message to some log. It can be a log file, console, stderr, socket, whatever. You must be able to view all log messages though, and searching and filtering them comes in handy too.

Why logging and not a debugger?
It gives you exactly the info you ask for.
It puts it in context, with other log messages. You can see when it happened in relation to other logged events. You can see how often it happened. You can see how the value changed over time.
You can easily filter what values you log when you have multiple objects and are interested in only one of them. Or only values above a threshold. Or both.
You can surround the code with log messages and find where the exception occurs even when you can’t get a stack trace (be sure to flush you log though).
You can do all this in the release build.
You can do it even when you code for console/mobile/set-top-box/toaster/whatever.
It’s easy to turn off when you release a build. And it can be useful when the problem happens on some other computer, not on yours.

Some pitfalls:
Make it easy to automatically flush the log after every message, it’s essential when diagnosing exceptions or freezing. Or flush it always (might be slow).
Make sure you actually log what you want to log (reviewing helps here). If you write wrong value to the log, it can mislead you for a while.

Visual aids

That’s not exactly logging, but it helps a lot in games. You can write bounding box coordinates to your log, but actually seeing the box on the screen with other objects is much more useful and effective.
Make it easy to add this form of “logging” to your code. Colored lines that fade out over time are useful, for example. You can add them anywhere in your code and see them on the screen for long enough (but not forever). You can make boxes, circles, spheres, arrows or whatever you want just writing a function that conveniently adds multiple lines based on the parameters you pass.
Visualizing AI state, targets, ranges etc is extremely useful too.

Debugging

If everything else fails, you can try the debugger. But what info can you get from it that the previous steps didn’t uncover? I guess doing more thinking or taking a break is better.

Posted in Uncategorized | Tagged , , | Comments closed

Mana gatherers

Mana gatherers are friendly creatures in Arcane Worlds who seek mana and bring it to your castle. They are spawned at your castle automatically.
Now, to open the portal to another world you need to collect enough mana in your castle. The castle also absorbs any mana dropped on it, so placing it strategically and fighting monsters near it could significantly speed up mana gathering.

The game is now in “alpha”, up from “pre-alpha”, so I raised the price to $10.
As usual, more info, demo download and purchase button are here.

Posted in Arcane Worlds | Tagged , , | Comments closed

Vacation

I’m leaving on vacation tomorrow, August 20th. I’ll be back on September 10th.
I won’t write code, but I’ll sketch out some ideas, monsters etc. for both Arcane Worlds and LEVEL UP!
I’m going to get a mobile internet for my tablet there and there should be wifi at the hotel, so I’ll be able to answer your comments and e-mails.

So, the next game updates will be at the end of September.

Posted in Uncategorized | Tagged , , | Comments closed

Arcane Worlds 0.07: Mana

Change list:
+ Killed monsters drop mana now
+ Spellcasting is now limited by player’s mana
+ When enough mana is accumulated, a portal to another world appears and monster spawning stops
+ A new spell to use portal to another world
+ Some worlds have flowing water now
+ Random sun position in new worlds
* Fixed castle spell bug (when shooting into the sky)
* Fixed wyvern shadow bug
* Fixed placeholder boxes rendering bug
* Minor engine improvements

It looks much more like a game now, so I’m going to change its status to “alpha” soon and raise the price to $10. For now, you can still grab it for $5 here and get all future updates for free.

I’m leaving on a vacation on August 20th. There might be another game update before that, if I’ll have enough time to finish it. Anyway, I’ll write another post before leaving.

Posted in Arcane Worlds | Tagged , , | Comments closed

New purchase system and gift keys

I’ve simplified the purchase system on my site, so you don’t have to register or log in to buy my games anymore.

Instead, you’ll get a special link (the key) which you can use to download the game and all future updates. If you’d ever forget the key, you can request it to be resend to your email. The system is similar to what the Humble Bundle uses.

The old system is still in place, so if you already bought a game you can download the updates just as you did before. If you want a new key however, please email me and I’ll arrange that. I’ll reuse the account system for blog comments later, so it’s not going away.

You can also buy gift keys to send to anyone or use yourself. They differ in that anyone can change the email the key is linked to, but only once. So when you send a gift key to someone, they can link the key to their email to retrieve it if they’d ever forget it.

You can buy multiple keys now, so feel free to do so if you want to support me.

If you encounter any problems, please tell me: support@ranmantaru.com

Posted in Uncategorized | Tagged , | Comments closed

Arcane Worlds 0.06

I’ve added first buildings. It looks like I need a building editor because coding them is cumbersome.

The most important building is your castle which you can now place with a spell. When you die (there’s player health now), you’ll respawn in the castle. If there’s no castle, you’ll be banished to another world (it would be universe map instead in the full game). The castle also accelerates health regeneration significantly. For now, the castle is indestructible.

I’m going to shape the gameplay further in the next updates. The goal is gatherable mana that’ll open a way to another world when you gather some critical amount of it.

Posted in Arcane Worlds | Tagged , , | Comments closed

LEVEL UP! 0.04

Well, it took much longer than I expected, mostly due to real-life issues.

The main features for this release are bonuses (health and upgrade points), explosive barrels and new rooms which make levels more varied.

I wanted to add more enemies, but I found the collision system to be quite buggy, especially in object-to-object collisions. So I rewrote it from scratch. The new collision system doesn’t distinguish between the level voxels and objects/characters, and it’s much faster. It’ll make adding destructible bosses much easier too. So, I decided to release it now as is, and add more enemies in the next version.

Demo download and more info about the game.

Posted in LEVEL UP! | Tagged , , , | Comments closed

First monsters in Arcane Worlds

They can hurt you, but the effect is limited to screen flash for now.
If you want to disable monsters to play with water or spells, press Ctrl-M.

More info and demo download.

Posted in Arcane Worlds | Tagged , , | Comments closed

Desura keys for LEVEL UP!

Desura keys are available now for those who bought LEVEL UP! from my site, or received it as a gift. You can get your key on your profile page.

Desura is an easier way to get game updates until I implement updating/patching in the launcher, but the updates might be a day or two late (compared to this site) since they must be approved by Desura staff.

Posted in LEVEL UP! | Tagged , | Comments closed

LEVEL UP! on Desura

You can get LEVEL UP! on Desura now. I’ll work on adding Desura keys for those who already purchased the game.

Desura Digital Distribution

I’ll put Arcane Worlds on Desura too (provided Desura is okay with that) after I sort out issues with LEVEL UP!

Posted in LEVEL UP! | Tagged | Comments closed