Skip to content

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:

GameApp.log("Hello world!");

Logging a Variable

You can also print a variable with its name for easier understanding:

int score = 10;
GameApp.log("Score", score);

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:

GameApp.warn("Player health is low!");

Error Messages

Errors are printed in red using GameApp.error(message). Use this for serious problems:

GameApp.error("Cannot load sprite!");

Debug Multiple Values

Sometimes you want to print several values in one line. Use GameApp.debug(...):

int x = 10;
int y = 20;
GameApp.debug("Player position:", x, y);

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:

int lives = 0;
GameApp.assertCondition(lives > 0, "Player should have at least 1 life!");

This will output: [ASSERT FAILED] Player should have at least 1 life!.

Use assertions to catch mistakes early while learning.