It's no secret debugging is where we developers spend most of our time. It is often a maddening task, but rewarding as we squash the errors in our code. It is while debugging that we find the craziest things.
I was building an arcade style top down space shooter a few years ago. It's up on freeware files if you want to goof off with it. It was called The Swarm. I was coding the enemy ships and wanted them to stalk the player so that they were more of a deadly nuisance. I made a mistake and didn't account for their travel speed. The resulting bug was amazing and far better than what I had envisioned. The enemy ships would sweep sideways toward the player but over shoot them, then sweep back only to overshoot them again. The zig zagging ships would slowly hone in on the player until they were right over them shuddering as they came in for the kill. Their movements make them very difficult to kill and are the defining feature of the game.
But I digress. Bugs are clever and disguise themselves. We must be careful not to cloud our minds with assumptions, even if we utterly certain. Case in point. The other night I encountered a bug in my game engine.
I had two sets of logic on a door.
1. Does the player have a key?
2. Is the door already unlocked.
2. Is the door already unlocked.
The first time through, with a key, the player successfully unlocked the door. The second time, when only the 'already unlocked' logic should fail I was getting both the key fail message and the already unlocked message. Somehow both were failing. But when I checked, the player did still have the key, yet that check was failing.
Or was it?
After a few hours of digging and outputting debugging messages, I checked the game database. And amazingly found that the already unlocked check had both messages as its fail message.
When the parser was translating the definitions into a game database, it looped through the logic sets, but wasn't clearing out the fail message with each iteration. Once I added the clear step, everything worked great.
When the parser was translating the definitions into a game database, it looped through the logic sets, but wasn't clearing out the fail message with each iteration. Once I added the clear step, everything worked great.
No comments:
Post a Comment