The Game Development Process:: Debugging
The Game Development Process:: Debugging
Introduction
Debugging is methodical process for removing
But debugging still frustrating Beginners not know how to proceed Even advanced can get stuck Dont know how long takes to find Variance can be high What are some tips? What method can be
applied?
Outline
5-step debugging process
Prevention
Game Maker specifics Debugging tips
code to print out values of arrow in air. But equals same value that crashes. Hypothesis is wrong. But now have new clue. Ex: suppose unit deleted before experience points added. Print out values of all in camp before fire and all deleted. Yep, thats it.
Or, 2) divide-and-conquer method (note, can use with hypothesis test above, too)
Sherlock Holmes: when you have eliminated the
impossible, whatever remains, however improbably, must be the truth Setting breakpoints, look at all values, until discover bug The divide part means break it into smaller sections
Repeat. Look for anomalies, NULL or NAN values
Ex: if crash, put breakpoint way. Is it before or after?
Ideally, want original coder to fix If not possible, at least try to talk with original coder for insights. Consider other similar cases, even if not yet
reported
as arrows did
programmer is sure they have fix (but programmer can be wrong!) So, test that solution repairs bug
Best by independent tester
ripple effect)
Outline
5-step debugging process (done)
Prevention
Game Maker specifics Debugging tips
(next)
Debugging Prevention
Add infrastructure, tools to assist Alter game variables on fly (speed up debugging) Visual diagnostics (maybe on avatars) Log data (events, units, code, time stamps) Indent code, use comments (in Game Maker)
Avoid duplicating code hard to fix if bug Use a script Avoid hard-coded values makes brittle Always initialize variables when declared Verify coverage (test all code) when testing
Outline
5-step debugging process (done)
Prevention
Game Maker specifics Debugging tips
(done) (next)
Save/load Look at instances, global variables, local variables Execute code Set speed
In code
global.fid = file_text_open_write(global.log_name);
end):
file_text_close(global.fid)
More file operations (look online) possible Note: files also useful for save/load game, etc.
Pay attention! Refers to: -Object -Event -Line number -Variable name
Help pinpoint problem Refer to object and method and offending code
Debugging Tips (1 of 3)
One thing at a time Fix one thing at a time dont try to fix multiple problems Change one thing at a time test hypothesis. Change back if doesnt fix problem. Start with simpler case that works - then add more complex code, one thing at a time Question your assumptions dont even assume
Debugging Tips (2 of 3)
Check code recently changed if bug appears,
may be in latest code (not even yours!) Use debugger breakpoints, memory watches, stack Break complex calculations into steps may be equation that is at fault or cast badly Check boundary conditions classic off by one for loops, etc. Minimize randomness
Ex: can be caused by random seed or player
Debugging Tips (3 of 3)
Take a break too close, cant see it. Remove
to provide fresh prospective Explain bug to someone else helps retrace steps, and others provide alternate hypotheses Debug with partner provides new techniques
Same advantage with code reviews, peer
programming