Working with Console
Calling a Console Command from Code
To call a console command from any of the scripts, you should call engine.console.run().
Source code (UnigineScript)
// 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.
Source code (UnigineScript)
To check the result, run the added 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;
}
Source code
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
Notice
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().
Source code (UnigineScript)
// disable the console
engine.console.setLock(1);
Last update: 2018-08-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)