Working with Console

Chapters:

To work with console commands from the code, UnigineConsole.h must be included:

Source code (C++)

#include <UnigineConsole.h>

Calling a Console Command from Code

To call a console command from the code, you should call the run() function.

Source code (C++)

// For example, to show messages:
Console::get()->run("show_messages 1");

Console commands (regardless of whether they were typed in the console or called from the code) cannot not be executed in the middle of the frame. Instead, they are executed in the beginning of the next frame not to interrupt the current rendering process and physics calculations.

Creating a Console Command

Implement a callback for a console command and a method for an action performed on the console command call. Both method should be implemented as AppWorldLogic instance methods.

Notice

If you want for the console command to take more than one argument, you need to implement a separate method per each number of arguments.

Get the console instance (which has a singleton implementation) and call addCommand() to add a new command.

In the example below, a new command takes no arguments or one argument. For this, three methods are declared in the AppWorldLogic.h header file:

choose_command() calls the appropriate method for the console command.