# User Defined Functions

User Defined Functions are custom functions made out of and parsable by [Airscript](../airscript/airscript-quick-start). They can be used as part of an application in the same way as out-of-the-box Airscript functions can, including when defining other User Defined Functions.

## The Building Interface for User Defined Functions

User Defined Functions are created in the [Connection Builder](../studio/builder-bar/connection-builder). Here is what the interface looks like:

![2021-11-02\_10-32-33.png](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-d8910371c935f732750cc8495b51158e5201a0bc%2Fudf-v1715-0.png?alt=media)

New User Defined Functions can be created by clicking the '+' icon next to **User Defined Functions** in the Tree and selecting **User Function Definition** from the menu that appears:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-ce8df60b69c554f372a30d4e979a6318d7a1e2cd%2Fudf-v1715-1.png?alt=media)

For a more detailed dive into how create a new User Defined functions step-by-step, check out [Creating Custom Functions](../building-apps/advanced/creating-custom-functions).

### Usage

Once a User Defined Function has been created, its **Usage** – that is, how the function will be called upon within the application – can be edited in the Inspector. User Defined Functions are referenced according to their Namespace and Binding, in the format **Namespace**#**Binding**. For instance, the following User Defined Function would be called upon as ABS\_CUBED#USER\_FUNCTION:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-317ac5dd4fd5af4c8a061b864d66ee55676c6ffb%2Fudf-v1715-2.png?alt=media)

### Behavior

The **Behavior** section in the Inspector provides the tools to edit the input and output that the User Defined Function will expect and return:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-97b0f38095f6196f14d55be64db33f84f58b4250%2Fudf-v1715-3.png?alt=media)

&#x20;

Airscript functions, User Defined Functions included, only return a single output. You can define the [data type](../variable-data-types/data-types-overview) of the output by selecting it from the dropdown menu directly underneath **Output**.

User Defined Functions can accept arbitrarily many inputs; new ones can be added by clicking on the '+' icon at the bottom of the **Inputs** field. Input defined in this way will be treated as required; the User Defined Function will not run without it. When the function is called upon, input must be given in the order it is listed here. For instance, for some example function EXAMPLE#USER\_FUNCTION, which the inputs are listed as follows:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-9aa6d7216d4ec29e8d00f390fd7f98705d1c3bc0%2Fudf-v1715-4.png?alt=media)

the function must be called upon as:

```javascript
EXAMPLE#USERFUNCTION(n, test, boolean)
```

The details of each input can be edited by clicking on them, at which point you'll be allowed to edit the name of the input (via the text field on the right) as well as define the [data type](../variable-data-types/data-types-overview) (by selecting from a dropdown menu on the left). An input can be deleted by clicking on the '-' icon to its right.

### Function Body

The **Function Body**, which dictates the behavior of the User Defined Function in terms of [Airscript](../airscript/airscript-quick-start) and the designated input, is defined and edited in the Stage. The **Function Body** accepts all valid Airscript operators, spanning everything from arithmetic operators to established functions (including other User Defined Functions). For instance, the following code utilizes the Airscript function [ABS](math-functions/abs) as well as the multiplication operator in order to return the absolute value of the cube of some input **n**:

![](https://1191388742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhOn9CLWoV9VfJeM5EDAa%2Fuploads%2Fgit-blob-e30aeb2645fbb336fd985e23634956ab8823574e%2Fudf-v1715-5.png?alt=media)
