# Sections

Sections are very similar to functions: they contain code, they (optionally) have some input variables and (optionally) give some output. One of the key differences being that sections can be created within a trigger.

## Creating a section

{% tabs %}
{% tab title="Syntax" %}

```
create [new] section [with [arguments variables] %-objects%] (and store it|stored) in %objects%
```

{% endtab %}
{% endtabs %}

The argument variables are a list of variables that represent the input of the section. Example: `with argument variables {_x}, {_y}`.

For section output, you have to use [return](https://tpgamesnl.gitbook.io/skript-reflect/custom-syntax/expressions#return).

The last expression is a variable in which the created section will be stored.

Local variables from before the creation of a section are available in the section itself, but won't modify the local variables from outside the section.

## Running a section

{% tabs %}
{% tab title="Syntax" %}

```
run section %section% [(1¦sync|2¦async)] [with [arguments] %-objects%] [and store [the] result in %-objects%] [(2¦and wait)]
```

{% endtab %}
{% endtabs %}

This effect will run the given section. If you run the section (a)sync, you can choose to wait for it to be done or not, by appending `and wait` or not.

{% hint style="info" %}
Note that you can't get output from running an async section without waiting for it to return.
{% endhint %}

You can specify arguments with this effect, for example like this: `with arguments {_a}, {_b}`.

The output of the section is stored in the result part: `and store result in {_result}`.

## Example

{% tabs %}
{% tab title="Example" %}

```
set {_i} to 2
create new section with {_x} stored in {_section}:
    return {_x} * {_i}
run section {_section} async with 3 and store result in {_result} and wait
broadcast "Result: %{_result}%" # shows 6
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Sections are very useful to use with [proxies](https://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/proxies), since you don't have to create functions for the proxy with sections.
{% endhint %}


---

# 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://tpgamesnl.gitbook.io/skript-reflect/advanced/reflection/sections.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.
