Working with Console
UnigineScript is deprecated and will be removed in future releases. Please consider using C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScipt is not guaranteed, as the current level of support assumes only fixing critical issues.
Calling a Console Command from Code#
To call a console command from any of the scripts, you should call engine.console.run().
// For example, to show messages:
// For example, to show messages:
engine.console.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#
To create a custom console command, you should:
- Implement a function that will be run on the console command call. If you want your console command to take more than one argument, you need to implement a separate function per each number of arguments.
- Call engine.console.addCommand() to add a new command.
// a script function to be executed for no arguments input
void console() {
log.message("console_command with no arguments has been called\n");
}
// a script function to be executed for 1 argument input
void console(string arg) {
log.message("console_command with 1 argument has been called\n Argument: %s\n", arg);
}
int init() {
// create a console command
engine.console.addCommand("console_command","console_command description","console");
return 1;
}
Unigine~# console_command
console_command with no arguments has been called
Unigine~# console_command arg
console_command with 1 argument has been called
Argument: arg
You can also remove custom console commands via engine.console.removeCommand().
Creating a Console Variable#
UnigineScript API doesn't provide the ability to add console variables.
Disabling Console#
To disable console (for example, for an application production version), you need to call engine.console.setLock().
// disable the console
engine.console.setLock(1);
Last update:
2020-05-19
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)