Debugging utilities
When you write games, it’s important to check what is happening in your code. Printing messages to the console helps you understand your program. GameApp provides several static methods to make debugging easier.
Logging a Simple Message
Use GameApp.log(message) to print a simple message to the console:
Logging a Variable
You can also print a variable with its name for easier understanding:
This will output: Score: 10
Warning Messages
Warnings are printed in yellow to stand out. Use GameApp.warn(message) when something might be a problem:
Error Messages
Errors are printed in red using GameApp.error(message). Use this for serious problems:
Debug Multiple Values
Sometimes you want to print several values in one line. Use GameApp.debug(...):
This will output: Player position: 10 20.
Assertions
Assertions let you check if something is true. If it’s false, a message is printed in red:
This will output: [ASSERT FAILED] Player should have at least 1 life!.
Use assertions to catch mistakes early while learning.