Debugging your game (Intermediate)

Debugging is one of those things that nobody really likes, but is very important to master. It can take hours, and because of Murphy's law you, most likely, don't have that time. Therefore, it is important to be systematic and know your tools well. After you are done finding the bug and implementing a fix, you should have a test in place. This way at least you will not have to go through the hell of debugging again.

PuDB is a visual full screen, console-based Python debugger that is easy to install. PuDB supports cursor keys and vi commands. The debugger can also be integrated with IPython, if required.

Getting ready

In order to install puDB, we only need to execute the following command:

sudo easy_install pudb

How to do it...

To debug the collision demo code, type the following command on the command line:

python -m pudb collision_demo.py

Tip

The source code should be available for download from the Packt Publishing website.

The following screenshot shows the most important debugging commands at the top:

How to do it...

We can also see the code being debugged, variables, the stack, and the defined breakpoints. Typing q exits most menus. Typing n moves the debugger to the next line. We can also move with the cursor keys or vi J and K keys to, for instance, set a breakpoint by typing b.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset