# Custom Functions

{% code lineNumbers="true" %}

```
function name(params)

end
```

{% endcode %}

Custom functions allow you to execute parts of your script when you want by triggering them.

{% code lineNumbers="true" %}

```
-- Define the function:
function myfunction(text)
    log(text)
end

-- Calls the function
myfunction("Hi")
```

{% endcode %}

You can also use return, which exits a function and optionally sends a value back to whoever called it.

{% code lineNumbers="true" %}

```
-- Return a value
function multiply(a, b)
  return a * b
end

var result = multiply(4, 3)
log(result) -- logs 12

-- Return early based on condition
function checkHealth(player)
  if get(player.health, player) < 5 then
    return "critical"
  end
  return "ok"
end

log(checkHealth(@p))
```

{% endcode %}


---

# 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://control-blocks-mod.gitbook.io/control-blocks-mod-docs/controlscript/custom-functions.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.
