This week Richard and I came across a bug in the time management game which we just couldn't solve. At some point, a visitor moves towards a so called 'free spot' (I wrote about this in another post) and moves to it's next target if it is available. Each visitor has points, and somehow when leaving a 'free spot' some visitors lost a point, which shouldn't be happening.
The hard part of this bug was that it didn't occur regulary, it was very hard to reproduce. So how did we solve this. We could have tried watching and playing the game over and over again figuring out what was going on when the bug occurs. Even while watching the game memory/variable values, it would take a lot of time to figure out what was happening. Therefore I decided to 'force' the game into the bug, well at least try to force it.
We let the game run until the bug occured. Then we paused the game and looked at the variables in the debugger. We did this a few times. Then we compared the memory data from the different situations to find matching values. The next step was to write a function which sets the game's variables, or better said, to 'force' the game's memory to specific values. The values to set to were the values we found to be matching when the bug occurs. When playing the game we ran the 'force game memory' function. After some small changes on the values to set, we were able to reproduce the bug. And find the piece of code which wasn't doing it's job properly.
So to conclude it all, if you're working on a system which has a lot of different variables it can be a real pain to find a bug. Creating a function which sets the game's memory to specific values which you record when the bug occurs can help you reproduce the bug much faster. Which then most of the time helps you find the bug much easier.