engine.console Functions
This set of functions controls console-related parameters.
void engine.console.addCommand (string name, string description, string function)
Adds a custom console command bound to a given script function. The command can have up to 6 arguments, which will be passed to the script function.
The example shows how to add a custom console command with 2 arguments:
namespace Test {
// A script function to be performed for no arguments input.
void my_command_callback() {
log.message("my_command callback\n");
}
// A script function to be performed for one argument input.
void my_command_callback(string arg_0) {
log.message("my_command callback arg_0 :%s\n",arg_0);
}
// A script function to be performed for two arguments input.
void my_command_callback(string arg_0,string arg_1) {
log.message("my_command callback arg_0:%s, arg_1:%s\n",arg_0,arg_1);
}
}
/*
*/
int init() {
engine.console.addCommand("my_command","my_command description","Test::my_command_callback");
return 1;
}
/*
*/
int shutdown() {
engine.console.removeCommand("my_command");
return 1;
}
// Input value: my_command
my_command callback
// Input value: my_command 1
my_command callback arg_0 :1
// Input value: my_command 1 2
my_command callback arg_0 :1 arg_1 :1
Arguments
- string name - Name of the new console command.
- string description - Short description to be displayed in the console.
- string function - Name of the target script function.
void engine.console.flush ()
Forces to execute all pending console commands. Be careful, since forced execution of some console commands (world_load, world_quit or state_restore that reload a currently executed script) can lead to a crash.int engine.console.getActivity ()
Returns a state of the console.Return value
1 if the console is active (opened); otherwise, 0.float engine.console.getFloat (string variable)
Returns a float value of a given variable.Arguments
- string variable - Variable name.
Return value
Value of the variable.int engine.console.getInt (string variable)
Returns an integer value of a given variable.Arguments
- string variable - Variable name.
Return value
Value of the variable.int engine.console.getLock ()
Checks if the console is disabled.Return value
1 if the console is disabled; otherwise, 0.string engine.console.getString (string variable)
Returns a string value of a given variable.Arguments
- string variable - Variable name.
Return value
Value of the variable.int engine.console.isCommand (string command)
Returns a value indicating if a command with a given name exists.Arguments
- string command - Command name.
Return value
1 if the command exists; otherwise, 0.int engine.console.isVariable (string variable)
Returns a value indicating if a variable with a given name exists.Arguments
- string variable - Variable name.
Return value
1 if the variable exists; otherwise, 0.void engine.console.print (string format, ... )
Prints a text to the console. Allows multiple arguments in the C printf() style.Arguments
- string format - Format of the text. See the formatting string description.
- ... - Arguments, multiple allowed.
void engine.console.removeCommand (string name)
Removes a custom console command.Arguments
- string name - Name of the custom console command.
void engine.console.run (string command, ... )
Runs a console command with its parameters. A formatted string should be passed: for example, "command" (no argument), "command %s" (string argument), etc.Arguments
- string command - Console command.
- ... - Arguments to the command, multiple allowed.
Examples
// Run a console command to load a world
engine.console.run("world_load menu");
// Run a console command to change DOF mode
int mode = 3;
engine.console.run("render_dof %d && render_restart",mode);
void engine.console.setActivity (int state)
Open or close the console. By default the console is closed.Arguments
- int state - Positive integer to make the console active (opened); otherwise, 0.
void engine.console.setBackgroundColor (vec4 color)
Sets a background color for the console.Arguments
- vec4 color - Four-component vector specifying the color in the RGBA format.
void engine.console.setErrorColor (vec4 color)
Sets a color for error messages in the console.Arguments
- vec4 color - Four-component vector specifying the color in the RGBA format.
void engine.console.setFloat (string variable, float value)
Sets a float value for a given variable.Arguments
- string variable - Variable name.
- float value - Value of the variable.
void engine.console.setInt (string variable, int value)
Sets an integer value for a given variable.Arguments
- string variable - Variable name.
- int value - Value of the variable.
void engine.console.setLock (int lock)
Disables or enables the console. By default the console is enabled.Arguments
- int lock - Positive integer to disable the console; otherwise, 0.
void engine.console.setMessageColor (vec4 color)
Sets a color for ordinary messages in the console.Arguments
- vec4 color - Four-component vector specifying the color in the RGBA format.
void engine.console.setPrompt (string prompt)
Updates the console prompt. The default prompt is Unigine~#.Arguments
- string prompt - New console prompt.
void engine.console.setString (string variable, string value)
Sets a string value for a given variable.Arguments
- string variable - Variable name.
- string value - Value of the variable.
void engine.console.setTextColor (vec4 color)
Sets a common font color for the console.Arguments
- vec4 color - Four-component vector specifying the color in the RGBA format.
void engine.console.setWarningColor (vec4 color)
Sets a color for warning messages in the console.Arguments
- vec4 color - Four-component vector specifying the color in the RGBA format.
Last update: 2017-07-03
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)