Game Development Reference
In-Depth Information
you have checked the Source checkbox in the Debug Control window), the first line of
code is highlighted in gray. Also, the Debug Control window shows that you are on line 1,
which is the import random line.
The debugger lets you execute one line or code at a time (called "stepping"). To execute
a single instruction, click the Step button in the Debug Window. Go ahead and click the
Step button once. This will cause the Python interpretter to execute the import random
instruction, and then stop before it executes the next instruction. The Debug Control
window will change to show that you are now on line 2, the import time line.
Stepping
Stepping is the process of executing one instruction of the program at a time. Doing
this lets you see what happens after running a single line of code, which can help you figure
out where a bug first appears in your programs.
The Debug Control window will show you what line is about to be executed when you
click the Step button in the Debug Control window. This window will also tell you what
line number it is on and show you the instruction itself.
Click the Step button again to run the import time instruction. The debugger will
execute this import statment and then move to line 4. The debugger skipped line 3
because it is a blank line. Notice that you can only step forward with the debugger, you
cannot go backwards.
Click the Step button three more times. This will execute the three def statements to
define the functions. The debugger skips over the def-blocks of these functions because we
are only defining the functions, not calling them. As you define these functions, they will
appear in the Globals area of the Debug Control window.
The text next to the function names in the Global area will look something like
"<function checkCave at 0x012859B0>". The module names also have confusing looking
text next to them, such as "<module 'random' from 'C:\\Python25\\lib\\random.pyc'>". This
is only useful to advanced Python programmers, and you don't need to know what this
means to debug your programs. Just seeing that the functions and modules are there in the
Global area will tell you if the function has been defined or the module has been imported.
You can also ignore the __builtins__, __doc__, and __name__ lines in the Global area.
The debugger will now be (after clicking Step four times) at line 35, the playAgain =
'yes' line. When you click Step to execute this line, the playAgain variable will be
created and will show up in the Global area. Next to it will be the value stored in this
variable, which is the string 'yes' . The debugger lets you see the values of all the
variables in the program as the run program runs. This can be very useful if you need to fix
your programs.
The Global area in the Debug Control window is where all the global variables are
Search WWH ::




Custom Search