This page has been translated automatically.
Programming
Fundamentals
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

engine.console Functions

Controls console-related parameters.

Adding Console Command with Several Arguments

The Console class can be used to create custom user console commands with a different number of arguments. This section provides an example of how to create a custom console command with several arguments.

Prior Knowledge
It is supposed that you have already created an empty UnigineScript project by using Unigine SDK Browser.

In the example below, we perform the following actions:

  • Define and implement methods for console commands.
  • Add a new command.
1. Implementing Callback Function

In this example, we define 2 functions in the unigine_project.cpp file: one as a callback for a console command with no arguments and one for a console command with 1 argument.

Source code (C#)
// unigine_project.cpp

// a script function to be executed for no arguments input
void console_action_callback() {
	log.message("first action! no arguments!\n");
}

// a script function to be executed for 1 argument input
void consoe_action_callback(string arg) {
	log.message("second action! the argument is: %s\n",arg);
}
2. Adding Custom Console Command

Add a custom command to the unigine_project.cpp file by using engine.console.addCommand() function. By adding this code into init() function, the engine adds a new console command on world initialization.

Source code (C++)
// unigine_project.cpp

/* ... */

int init() {
	// add a command
	engine.console.addCommand("console_action","my_command description","my_command_callback");
	
	return 1;
}

/* ... */
3. Running Sample

Run the project and open the console. Write recently created command to check the result:

Output
#if you write "console_action"
console_action
first action! no arguments!

#if you write "console_action arg"
console action arg
second action! the argument is: arg

To remove the added console command, use removeCommand() method.

Console Class

Members


int engine.console.addCommand(string name, string desc, string callback)

Adds a custom console command bound to a given callback function. The command can have up to 6 arguments, which will be passed to the script function.

Arguments

  • string name - Name of the new console command.
  • string desc - Short description to be displayed in the console.
  • string callback - Name of the callback function that is run on command execution.

Return value

1 if the custom command is added successfully; otherwise, 0.

int engine.console.removeCommand(string name)

Removes a custom console command.

Arguments

  • string name - Name of the custom console command.

Return value

1 if the custom command has been removed successfully; otherwise, 0.

void engine.console.run(string command)

Runs the specified console command.

Arguments

  • string command - A console command with arguments.

void engine.console.flush()

Forces to execute all queued console commands.

void engine.console.print(string text)

Prints the given text in the console.

Arguments

  • string text - Text to be printed in the console.

void engine.console.setActivity(int activity)

Open or close the console. By default the console is closed.

Arguments

  • int activity - Positive integer to make the console active (opened); otherwise, 0.

int engine.console.getActivity()

Returns a state of the console.

Return value

1 if the console is 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.

int engine.console.isCommand(string name)

Returns a value indicating if a command with a given name exists.

Arguments

  • string name - The command name.

Return value

1 if the command exists; otherwise, 0.

string engine.console.getCommandDescription(string name)

Returns the description of the console command by its name. If the name isn't specified, an empty string will be returned.

Arguments

  • string name - The command name.

Return value

The command description if it exists; otherwise, an empty string.

string engine.console.getCommandName(int num)

Returns the name of the console command by its number in the array of the existing commands.

Arguments

  • int num - The command number.

Return value

The command name if it is found in the array of the existing commands; otherwise, an empty string.

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 name, float value)

Sets a float value for a given variable.

Arguments

  • string name - The variable name.
  • float value - Float value of the variable.

float engine.console.getFloat(string name)

Returns a float value of a given variable.

Arguments

  • string name - The variable name.

Return value

Float value of the variable.

int engine.console.isFloat(string name)

Checks if the value set for the given console variable is of the float type.

Arguments

  • string name - The variable name.

Return value

1 if the variable value is float; otherwise, 0.

void engine.console.setInt(string name, int value)

Sets an integer value for a given variable.

Arguments

  • string name - Variable name.
  • int value - Value of the variable.

int engine.console.getInt(string name)

Returns an integer value of a given variable.

Arguments

  • string name - Variable name.

Return value

Value of the variable.

int engine.console.isInt(string name)

Checks if the value of the given console variable is of the integer type.

Arguments

  • string name - The variable name.

Return value

1 if the variable value is int; otherwise, 0.

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.

int engine.console.getLock()

Checks if the console is disabled.

Return value

1 if the console is disabled; 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.

int engine.console.getNumCommands()

Returns the number of all available console commands, incuding the custom ones.

Return value

The number of available console commands.

int engine.console.getNumVariables()

Returns the number of all available console variables.

Return value

The number of available console variables.

void engine.console.setPrompt(string str)

Updates the console prompt. The default prompt is Unigine~#.

Arguments

  • string str - New console prompt.

void engine.console.setString(string name, string value)

Sets a string value for a given variable.

Arguments

  • string name - The variable name.
  • string value - String value of the variable.

string engine.console.getString(string name)

Returns the string value of a given variable.

Arguments

  • string name - The variable name.

Return value

String value of the variable.

int engine.console.isString(string name)

Checks if the value of the given console variable is of the string type.

Arguments

  • string name - The variable name.

Return value

1 if the variable value is string; otherwise, 0.

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.

int engine.console.isVariable(string name)

Returns a value indicating if a variable with a given name exists.

Arguments

  • string name - The variable name.

Return value

1 if the variable exists; otherwise, 0.

string engine.console.getVariableDescription(string name)

Returns the description of the console variable by its name. If the name isn't specified, an empty string will be returned.

Arguments

  • string name - The variable name.

Return value

The variable description if it exists; otherwise, an empty string.

string engine.console.getVariableName(int num)

Returns the name of the console variable by its number in the array of the existing variables.

Arguments

  • int num - The variable number.

Return value

The variable name if it is found in the array of the existing variables; otherwise, an empty string.

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.

int CONSOLE_LEVEL_ERROR

Description

An error message.

int CONSOLE_LEVEL_NORMAL

Description

An ordinary message.

int CONSOLE_LEVEL_WARNING

Description

A warning.
Last update: 2017-07-03
Build: ()