# Catching Commands

{% hint style="warning" %}
This page was written using AI. No idea if it really works! :man\_shrugging:
{% endhint %}

The Ultimate Chat Box has many different events available. In this tutorial though, we will be taking a look at the OnInputFieldCommandUpdated and OnInputFieldCommandSubmitted events. Each of them have different uses, so let's dive into it!

## OnInputFieldCommandUpdated

The OnInputFieldCommandUpdated events is invoked any time the input field is updated with a potential command. This can be useful for providing auto-complete suggestions for your players, like inviting other players or playing emotes.

Here is a simple example:

```csharp
private void OnInputFieldCommandUpdated(string command)
{
    if (string.IsNullOrEmpty(command)) return;

    // Assume _suggestions is a List of possible autocompletions
    _suggestions.Clear();

    // Filter suggestions based on the current command input
    foreach (var suggestion in _possibleCommands)
    {
        if (suggestion.StartsWith(command, StringComparison.OrdinalIgnoreCase))
        {
            _suggestions.Add(suggestion);
        }
    }

    // Show suggestions to the user
    UpdateSuggestionsUI(_suggestions);
}

private void UpdateSuggestionsUI(List<string> suggestions)
{
    // Code to update the UI with the suggestions goes here
}
```

### OnInputFieldCommandSubmitted

The OnInputFieldCommandSubmitted event is triggered when the player submits a command through the input field. It's the perfect place to handle the execution of commands.

Here is an example on how to use this event:

```csharp
private void OnInputFieldCommandSubmitted(string command)
{
    // Execute the command if it's recognized
    if (_possibleCommands.Contains(command))
    {
        ExecuteCommand(command);
    }
    else
    {
        // Inform the user that the command is not recognized
        ShowErrorMessage("Unrecognized command: " + command);
    }
}

private void ExecuteCommand(string command)
{
    // Code to execute the recognized command goes here
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tankandhealerstudio.com/assets/ultimatechatbox/tips-and-tricks/catching-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
