# 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://541806160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJE1tNTWPRG3py6Cs3USD%2Fuploads%2FCXqGQa0BfAo5oW5UmaUt%2Ftextanimatorgif2febucci.gif?alt=media" 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

public Febucci.UI.Core.TypewriterCore typewriter;

//Adds and removes listening to callback
void OnEnable() => typewriter.onMessage.AddListener(OnTypewriterMessage);
void OnDisable() => typewriter.onMessage.RemoveListener(OnTypewriterMessage);

//Does stuff based on event
void OnTypewriterMessage(Febucci.UI.Core.Parsing.EventMarker eventMarker)
{
    switch (eventMarker.name)
    {
        case "something":
            // do something
            break;
    }
}
```

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

You can find the [EventMarker API here](https://www.api.febucci.com/tools/text-animator-unity/api/Febucci.UI.Core.Parsing.EventMarker.html), for example to get all the parameters of the event (if any).


---

# 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.febucci.com/text-animator-unity/2.x/typewriter/trigger-events-when-typing.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.
