# Trigger Events when typing

Events are special tags that let you send messages (string) to any listener script, once the typewriter has reached a specific part of the text. *(For this reason, events work only if the typewriter is enabled)*

<figure><img src="https://content.gitbook.com/content/XuXUTa2X5PYuYL6yRvl1/blobs/3UxVpaMvfQpqNMeoWA2v/textanimatorgif2febucci.gif" alt="textanimatorgif2febucci"><figcaption><p>Scene 'Example 3 - Events'</p></figcaption></figure>

***

## Overview <a href="#overview" id="overview"></a>

You can write events in your text by using rich text tags.

### Formatting <a href="#formatting" id="formatting"></a>

Event’s messages are preceded by a question mark, like this: `<?eventMessage>`.

**Example:** To call an event named ‘shakeCamera’, write: `<?shakeCamera>`

* 👍🏻 An event can have any kind of tag, including built-in effect’s ones.
* ⚠️ Events are case sensitive. Writing `<?camshake>` is not the same as writing `<?camShake>`. Be careful! (or use the `string.ToLower()` method in your scripts to account for that.)

### Parameters <a href="#parameters" id="parameters"></a>

Events can have one or multiple parameters (starting with the `=` sign for the first, and then separating the others with a comma `,`), to allow you to send multiple data to your scripts.

* One parameter: `<?eventID=parameter1>`, will result in a message “eventID” and one parameter “parameter1”.
* Multiple parameters: `<?eventID=p1,p2>`, will result in a message “eventID” and parameters “p1” and “p2”.

***

## Listening to events <a href="#listening-to-events" id="listening-to-events"></a>

The scripts that you want to listen from events/messages must subscribe to the `onMessage` callback inside the `Typewriter` class. ([Scripting Api](https://www.api.febucci.com/tools/text-animator-unity/api/Febucci.UI.Core.TypewriterCore.html#Febucci_UI_Core_TypewriterCore_onMessage)).

Example:

```csharp
// inside your script
[SerializeField] TypewriterComponent typewriter;

// adds and removes callbacks
void OnEnable() => typewriter.onMessage.AddListener(OnMessage);
void OnDisable() => typewriter.onMessage.RemoveListener(OnMessage);

// does stuff based on the received marker
void OnMessage(EventMarker marker)
{
    switch (marker.name)
    {
        // once the typewriter meets the "<?something>" tag
        
        case "something":
            // do something
            break;
    }
}
```

👍🏻 Note how the “message” string has no ‘<‘, ‘?’ and ‘>’ characters, but only contains the message.
