Game Development Reference
In-Depth Information
7 - Using the Debugger
have the debugger keep stepping until the function was over and returned to the line after
the call to displayIntro() . Stepping out can save you from having to click Step over
and over again to jump out of the function.
If you are not inside a function (that is, you are in the global scope) and you click Out,
the debugger will execute all the remaining lines in the program (exactly as if you clicked
the Go button).
The last kind of stepping is done by the Over button in the Debug Control window, and
it is for stepping over function calls. Stepping over means that the debugger will not step
into function calls. Instead, the debugger executes all the code inside the function at once
and only stop at the line after the function call. This is useful if you do not want to step
through every single line inside the function.
You now know what the five buttons at the top of the Debug Control window do. Here's
a recap:
— Go - Executes the rest of the code as normal, or until it reaches a break point. (Break
points are described later.)
— Step - Step one line of code. If the line is a function call, the debugger will step into
the function.
— Over - Step one line of code. If the line is a function call, the debugger will not step
into the function, but instead step over the call.
— Out - Keeps stepping over lines of code until the debugger leaves the function it was
in when Out was clicked. This steps out of the function.
— Quit - Immediately terminates the program.
Find the Bug
Using the debugger is a good way to figure out what is causing bugs in your program. As
an example, here is a small program that has a bug in it. The program comes up with a
random addition problem for the user to solve. In the interactive shell window, click on
File, then New Window to open a new file editor window. Type this program into that
window, and save the program as buggy.py .
buggy.py
1. import random
2. number1 = random.randint(1, 10)
3. number2 = random.randint(1, 10)
4. print('What is ' + str(number1) + ' + ' + str(number2) +
'?')
5. answer = input()
6. if answer == number1 + number2:
7. print('Correct!')
8. else:
9. print('Nope! The answer is ' + str(number1 +
Search WWH ::




Custom Search