This Addon provides a flexible in-game developer console system, allowing you to register custom command and execute them during runtime. You can easily add commands with or without parameters, including optional arguments, and provide descriptions and usage examples for each. The console supports toggling visibility, pause the game when opened. The console can be disabled for release builds if not needed. It also include methods to update the settings for the console, such as changing the toggle key or change command colors.
Quickstart
Register a command
Console.register_custom_command("reload", _reload, [], "Reload current scene")
func _reload() -> String:
get_tree().reload_current_scene()
return "reloaded scene"
This will add an command where the arguments are provided as Strings, your method accepting those arguments will get strings as well you will need to convert to the correct data type all by yourself.
Register a strong argument command
Console.register_custom_strong_command("spawn_entity",
_spawn_entity,
[CommandArgument.new(CommandArgument.Type.INT, "X Position", "The x position on screen for the entity"),
CommandArgument.new(CommandArgument.Type.INT, "y Position", "The y position on screen for the entity"),
CommandArgument.new(CommandArgument.Type.FLOAT, "time to life", "The time the entity should life in seconds")
],
"Spawn an example entity at a global position",
"",
["spawn_entity 200 300 4"]
)
func _spawn_entity(pos_x: int, pos_y: int, ttl: float) -> String:
pass
Use the fluent builder (0.6.2 and later)This will add a new argument but the argument types are defined, this will parse the input data automatically making it easier to use in your method. If a wrong type was provided to any of the arguments an error will be thrown preventing the method execution.
Allows you to create your commands with a fluent builder, making the process of creation much more readable.
Console.register_command(Command.create("echo")
.calling_method(_echo_text)
.with_argument(CommandArgument.create("text")
.of_type(CommandArgument.Type.STRING)
.with_description("echo a given text on the console")
.with_predefined_value("Hello")
.with_predefined_value("Bye")
.finalize())
.documentation()
.with_description("Command to print text to the console")
.with_long_description("This command does allow you to echo some text provided back to the console")
.add_example("echo test")
.finish()
)
Unregister a command
Console.remove_command("reload")
Check if a command exists
if Console.command_is_registered(my_custom_command):
print("command %s is registerd" % my_custom_command.get_command_name())
if Console.command_name_is_registered(my_custom_command.get_command_name()):
print("command %s is registerd" % my_custom_command.get_command_name())
Other important Options
## Change the console settings
## There are more options
Console.update_console_settings(func(settings: ConsoleSettings):
## Set key to toggle console
settings.open_console_key = KEY_F12
## Pause game tree if console does open up
settings.pause_game_if_console_opened = true
)
## Hide console
Console.hide_console()
## Show console
Console.show_console()
## Disable console completely, can be used to remove it on release builds
Console.disable()
## Enable a disabled console
Console.enable()
Navigation
If inside the command input field use the arrow up and down key to navigate the history, if any. If there is a command which can be autocompleted to it will be shown below the input field, to select the suggestion simply click "tab", to traverse the list backward use "shift + tab".
:information_source: You can change the button to navigate the autocomplete entries via the console settings.
To send a command to the console, simple press enter. If a command is written in red no matching command was found, if it is written in green you are good to go, keep in mind that this will not check if all the arguments are provided correctly.
Built in commands
This is a list with build in commands and there purpose
| Name | Description | example |
|---|---|---|
| list_commands | This will list all the built in and custom commands currently available | list_commands |
| clear | Clear the output of the console window | clear |
| man | Get a more detailed description of a command, also including examples if any. Requires the command name as a argument | man clear |
| pause | Pause the game by pausing the root tree | pause |
| unpause | unpause the game by unpausing the root | unpause |
| quit | Close the game, does not work on a web build. | quit |
| help | Get help about the console, this will list the name, version and a short help text | help |
Changelog for version 0.6.3
No changelog provided for this version.