# Functions and Events

In Midio, functions take input from the left and provide output on the right. Unlike most programming languages, such as JavaScript, Python, or C, Midio functions can produce multiple outputs. Functions in Midio are similar to those in other languages, and they form alongside events the core components of the language. Almost every node in Midio is either a function or an event. For information the builtin functions and events in Midio, refer to the [standard library](/midio-docs/built-in-nodes.md).

<figure><img src="/files/TDmjOvjY1rqbLIGczudn" alt="" width="348"><figcaption></figcaption></figure>

### Triggers

Some functions and events also has triggers, which are the green sockets. Functions with triggers need to be explicitly 'triggered' in order to be called, while non-triggable functions (functions without any triggers), are called 'on-demand', if connected to a node that is called.

<figure><img src="/files/4y33jyG9FugdmAKEWtLg" alt="" width="563"><figcaption></figcaption></figure>

## ## Making your own functions

You can easily make your own functions, either by selecting a group of nodes and using 'Convert to Function' from the right-click/context menu, or by right clicking a module in the modules over view and clicking **'Add function here'.**

<figure><img src="/files/ieUxh6w3AWgBRXRnXc52" alt="" width="273"><figcaption><p>Add new function to the Main module.</p></figcaption></figure>

<figure><img src="/files/Cw1vKjhT65sybJx0zWnM" alt="" width="323"><figcaption><p>Convert to function</p></figcaption></figure>

### Adding inputs and outputs to your function

You can add inputs and output, either through the node-menu (space bar), or by **control-clicking** the canvas while your adding a new arrow. This will automatically add a new input/output to your function, and hook it up to the arrow you started.

TODO: Screen capture

#### Trigger input/output

Triggers don't require much setup to use, but can optionally declare what context they consume or borrow (for inputs) or produce (for outputs). Contexts is a slightly advanced topic that you can read more about [here](/midio-docs/reference/the-midio-language/contexts.md).

<figure><img src="/files/MUhnfX1HrleXckxCI97a" alt="" width="375"><figcaption></figcaption></figure>

#### Data input/output

Data inputs can be assigned a type[ (read more about types here)](/midio-docs/reference/the-midio-language/data-type.md), if you want to be specific about the kinds of data it expects. If you don't care about the type, assign it to the `Any`type. Use the dropdown menu on the input/output node to assign a new type.

<figure><img src="/files/e23qj1AotvhA4wgncefb" alt="" width="375"><figcaption><p>You can change the type of data your inputs or outputs expect.</p></figcaption></figure>

## Events

Events are used to trigger flows, based on a variety of external conditions, like receiving an [HTTP request](/midio-docs/built-in-nodes/http.md#endpoint), or on a [schedule](/midio-docs/built-in-nodes/core-std.md#scheduling).

Events have a green header, and never any input triggers.

<figure><img src="/files/Vu3WC6glhV7ytZpKCXqC" alt="" width="563"><figcaption></figcaption></figure>


---

# 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.midio.com/midio-docs/reference/the-midio-language/functions-and-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.
