> For the complete documentation index, see [llms.txt](https://help.vectary.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.vectary.com/api/model-api/api-reference/dispatchevent.md).

# dispatchEvent

#### dispatchEvent

Sends an event to the scene. Used to trigger Interactions that have "Event listener" as their trigger.

#### **Signature**

```typescript
dispatchEvent(eventName: string, value?: any): Promise<void>
```

#### **Parameters**

<table><thead><tr><th width="176.37890625">Parameter</th><th width="135.375">Type</th><th width="108.88671875">Required</th><th>Description</th></tr></thead><tbody><tr><td>eventName</td><td>string</td><td>Yes</td><td>Name of the event to dispatch</td></tr><tr><td>value</td><td>any</td><td>No</td><td>Value to send with the event</td></tr></tbody></table>

#### **Returns**

`Promise<void>`

#### **Usage**

```javascript
// Send event without value
await api.dispatchEvent("reset");

// Send event with number
await api.dispatchEvent("width", 150);

// Send event with string
await api.dispatchEvent("color", "red");
```

#### **How it works**

1. Call `dispatchEvent()` from your website
2. In Studio, an Interaction with trigger **Event listener** and matching event name receives it
3. The Interaction executes its action (Transform, Set variable, Play animation, etc.)

If a Variable with the same name exists, its value is updated with the sent value.

#### **Supported value types**

| Type                 | Example          | Received as                   |
| -------------------- | ---------------- | ----------------------------- |
| Number               | `42`, `3.14`     | ✅ number                      |
| String               | `"hello"`        | ✅ string                      |
| Boolean              | `true`, `false`  | ✅ boolean                     |
| Array                | `[255, 128, 0]`  | ⚠️ First element only (`255`) |
| Object               | `{r: 255, g: 0}` | ⚠️ First value only (`255`)   |
| null                 | `null`           | ⚠️ Becomes `0`                |
| undefined / no value | `undefined`      | ⚠️ Becomes `0`                |

**Notes**

* Event name must match the name in Studio's Event listener trigger
* If no Variable with the event name exists, the value is not stored (but the event still triggers)
* For complex data, consider sending individual values or JSON-encoded strings


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://help.vectary.com/api/model-api/api-reference/dispatchevent.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
