# 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
}
```
