Skip to content

Commit

Permalink
Add Debug Commands docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mafiesto4 committed Oct 27, 2024
1 parent 93405de commit 520f0d7
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
6 changes: 6 additions & 0 deletions manual/editor/windows/output-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
The **Output Log** is a utility window that displays the current engine log. Can be used to detect problems with the game or to analyze the engine workload.

You can easily select and copy parts of the log, use the *Search* box to filter entries or use the log types filter under the **View** dropdown menu. Also, loading log files is supported which can be used to read and analyze the logs from the build version of the game (eg. from Xbox dev build).

### Debug Commands

![Debug Commands in Output Log](../../scripting/advanced/media/debug-commands-output-log.gif)

At the bottom of that window, there is an input command field that can be used to run [Debug Commands](../../scripting/advanced/debug-commands.md). You can type commands with an automatic search popup that displays similar commands based on the entered value. Use arrow keys to navigate around that popup list. The tab key can be used to autocomplete commands based on the best-found match. Finally, when input is empty you can use the arrow up key to navigate around the command history and re-try one of them again.
103 changes: 103 additions & 0 deletions manual/scripting/advanced/debug-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Debug Commands

`DebugCommand` is an attribute that can be placed on classes, fields, methods, and properties to expose them to Debug Commands interface which can be used for configuration, modding, or tooling.

> [!TIP]
> Only `static` members can be used in debug commands.
## Access

### Output Log

![Debug Commands in Output Log](media/debug-commands-output-log.gif)

[Output Log](../../editor/windows/output-log.md) is Editor window that displays the full log. At the bottom of that window, there is an input command field that can be used to run commands. You can type commands with an automatic search popup that displays similar commands based on the entered value. Use arrow keys to navigate around that popup list. The tab key can be used to autocomplete commands based on the best-found match. Finally, when input is empty you can use the arrow up key to navigate around the command history and re-try one of them again.

### In-game console

![Debug Commands In Game](media/debug-commands-in-game.png)

Debug Commands can appear within an in-game console or debug tooling. For example, [Arizona Framework](https://github.com/FlaxEngine/ArizonaFramework) implements console via [ImGui](https://github.com/FlaxEngine/ImGui). Such tool can be useful when developing games for various platforms and devices such as consoles where game configurations can be tweaked at runtime.

### `DebugCommands` API

Use `DebugCommands` class to execute or list debug commands within the project. It caches all commands for engine, game, and plugin projects.

Example usage:

# [C#](#tab/code-csharp)
```cs
// Disable vsync
DebugCommands.Execute("Graphics.UseVSync false");
```
# [C++](#tab/code-cpp)
```cpp
// Disable vsync
DebugCommands::Execute(TEXT("Graphics.UseVSync false"));
```
***
## Example
# [C#](#tab/code-csharp)
```cs
using FlaxEngine;
/// <summary>
/// Global gameplay configs.
/// </summary>
[DebugCommand]
public static class GameGlobals
{
/// <summary>
/// Disables player damage.
/// </summary>
public static bool GodMode = false;
}
/// <summary>
/// Player script.
/// </summary>
public class PlayerLogic : Script
{
/// <summary>
/// Player speed scale.
/// </summary>
[DebugCommand]
public static float SpeedScale = 1.0f;
/// <summary>
/// Restores player HP to max.
/// </summary>
[DebugCommand]
public static void HealPlayer()
{
//..
}
}
```
# [C++](#tab/code-cpp)
```cpp
// Global gameplay configs.
API_CLASS(Static, Attributes="DebugCommand") class GAME_API GameGlobals
{
DECLARE_SCRIPTING_TYPE_NO_SPAWN(GameGlobals);
public:
// Disables player damage.
API_FIELD() static bool GodMode;
};

// Player script.
API_CLASS() class GAME_API PlayerLogic : public Script
{
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE(PlayerLogic);
public:
// Player speed scale.
API_FIELD(Attributes="DebugCommand") static float SpeedScale;

// Restores player HP to max.
API_FUNCTION(Attributes="DebugCommand") static void HealPlayer();
};
```
***
1 change: 1 addition & 0 deletions manual/scripting/advanced/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
* [Tags](tags.md)
* [Run code on module load](code-on-load.md)
* [File Reference](file-reference.md)
* [Debug Commands](debug-commands.md)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions manual/scripting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ To start visual scripting see the related documentation [here](visual/index.md).
* [Tags](advanced/tags.md)
* [Run code on module load](advanced/code-on-load.md)
* [File Reference](advanced/file-reference.md)
* [Debug Commands](advanced/debug-commands.md)
* [Artificial Intelligence](ai/index.md)
* [Behavior Trees](ai/behavior-trees/index.md)
* [Behavior Knowledge](ai/behavior-trees/knowledge.md)
Expand Down
1 change: 1 addition & 0 deletions manual/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
### [Tags](scripting/advanced/tags.md)
### [Run code on module load](scripting/advanced/code-on-load.md)
### [File Reference](scripting/advanced/file-reference.md)
### [Debug Commands](scripting/advanced/debug-commands.md)
## [Artificial Intelligence](scripting/ai/index.md)
### [Behavior Trees](scripting/ai/behavior-trees/index.md)
#### [Behavior Knowledge](scripting/ai/behavior-trees/knowledge.md)
Expand Down

0 comments on commit 520f0d7

Please sign in to comment.