-
Notifications
You must be signed in to change notification settings - Fork 21
Console commands
You can register new console commands which can trigger existing or new events with additional parameters.
Registering a new console command
C++ and AngelScript
VariantMap data;
data["ConsoleCommandName"] = "help"; //Actual console command
data["ConsoleCommandEvent"] = "ConsoleHelp"; // Event that will be triggered when console command is entered
data["ConsoleCommandDescription"] = "Displays all available commands"; // Short description for console command
SendEvent("ConsoleCommandAdd", data);
When you input registered command in the console, you can also pass additional parameters. When you input something like help 123
, ConsoleHelp
event will be triggered and it will also contain String array with all the parameters, in this case:
[
"help",
"123"
]
you can retrieve these values in the following way
AngelScript
void HandleConsoleHelp(StringHash eventType, VariantMap& eventData)
{
Array<String> params = eventData["Parameters"].GetStringVector();
}
C++
void HandleConsoleHelp(StringHash eventType, VariantMap& eventData)
{
StringVector params = eventData["Parameters"].GetStringVector();
}
Console also supports autocomplete which will contain all registered commands!
You can also rewrite any global configuration parameter via the console, all you have to do is provide it's name as a console command.
Example: console command FullScreen
will return it's value. Console command FullScreen true
or Fullscreen 1
will set a new value for it.
Of course changing the variable value itself won't do anything, so when any of the variables are changes, ConsoleGlobalVariableChanged
event is sent out. It contains 2 parameters - GlobalVariableName
and GlobalVariableValue
. Both parameters are strings, but if you would like to get the value in correct format, just call GetGlobalVar()
function again.