Using the Debugger
When the problem isn’t evident despite thinking it through thoroughly, you can turn to the debugger for help. Use the debugger to step through the code and inspect values as they change. Add a breakpoint near the error, and then step through while observing variable and expression values. Compare their actual values to what you expected them to be.
This is where features such as logpoints and data inspection tools can come in handy. You can set logpoints output values as the program runs, or use data inspection tools to watch the values of expressions as you step through the program. Logpoints are particularly helpful for more interactive programs such as the games, as it can log the value of the expression without needing to stop the program running.