# Events

Events will be triggered on different circumstances like, on click, on enabled, on message receive etc. Events can call/trigger actions.

With plugins you can add and call/emit your own events and define when they should be executed as well parse date within these events.&#x20;

***

## Register an Event

Within the <mark style="color:purple;">`afterInit`</mark> function, the following code will add an event:

```python
def afterInit(self):
    self.registerEvent(NameString, IdentifyerString)
```

#### Example

```python
self.registerEvent("Example Event Name", "ExampleEventIdentifyer")
```

Two comma separated strings are necessary to register the event properly:

* The first string is defining the name how a user would find the event within the menu.
* The second one is the name of the event itself and the identifier to call it.

<figure><img src="/files/z89h5drxiUBBNK2k8LHh" alt=""><figcaption></figcaption></figure>

***

## Emit / Call an Event

To call/emit the event, the following code is required:

```python
self.emitEvent(IdentifyerString)
```

#### Example

```python
self.emitEvent("ExampleEventIdentifyer")
```

Whenever within your code you are calling this function, the event will be emitted/triggered.

{% hint style="warning" %}
Make sure the ***IdentifyerString*** is matching from the register
{% endhint %}

***

## Register an Event with a parameter

```python
self.registerEvent("Name", "Identifyer", scriptTokens=["Value"])
```

The **`scriptTokens=` is a variable of a type List.**

{% hint style="info" %}
**The `scriptToken=[""]` parameter is optional.**&#x20;

**These create/register the given parameter names within the data structure also if they will be not used from the "call" return.**

If these are not set, they will be shown but empty within the data value tree.
{% endhint %}

***

## Emit / Call an Event with a parameter

```python
self.emitEvent("Identifyer", sp.ValueTree.fromDict({"Value": 123},"root"))
```

***

## Register an Event with parameters

```python
self.registerEvent("Name", "Identifyer", scriptTokens=["Value", "Value2", "Value3"])
```

{% hint style="info" %}
**The `scriptToken=[""]` parameter is optional.**&#x20;

**These create/register the given parameter names within the data structure also if they will be not used from the "call" return.**

If these are not set, they will be shown but empty within the data value tree.
{% endhint %}

## Emit / Call an Event with parameters

```python
data = sp.ValueTree("root")
data["someData"].value = 123
data["moreData"].value = False

self.emitEvent("Identifyer", data)
```

or from Dict:

```python
someDict = {"someData": 123, "moreData", False}

self.emitEvent("Identifyer", sp.ValueTree.fromDict(someDict),"root")
```


---

# 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://stage-precision.gitbook.io/grid/extensions/events.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.
