# Global Functions

Below is a list of all global functions. By “global”, we mean these functions do not require a preceding namespace - so you can call them directly, unlike other functions.

## print﻿ <a href="#print" id="print"></a>

<mark style="color:blue;">**`Function`**</mark>

Prints text to game's console. Automatically inserts a space between parameters.

#### Arguments

| Name  | Type | Description                     |
| ----- | ---- | ------------------------------- |
| `...` | ...  | Values to print in the console. |

**Example**

```lua
print('Hello world!', 123); -- prints out "Hello world! 123" to the console
```

***

## error﻿ <a href="#error" id="error"></a>

<mark style="color:blue;">**`Function`**</mark>

Prints an error text to game's console, and shuts down the script. Try to avoid using this function - use it only if an error happens which you can't recover from.

#### Arguments

| Name   | Type   | Description                               |
| ------ | ------ | ----------------------------------------- |
| `text` | string | Read [`print`](#print) for documentation. |

**Example**

```lua
error('Can't recover from this one! Error: ' .. tostring(123));
```

***

## unpack <a href="#error" id="error"></a>

<mark style="color:blue;">**`Function`**</mark>

Unpacks a table of elements.

#### Arguments

| Name  | Type    | Description |
| ----- | ------- | ----------- |
| `tbl` | `table` | Any table   |

**Example**

```lua
local message = { 'Hello', 'World' }
print(unpack(message)) -- 'Hello world'
```

***

## Delay <a href="#error" id="error"></a>

<mark style="color:blue;">**`Function`**</mark>

Delays a callback by a certain amount of time, in seconds.

#### Arguments

| Name       | Type       | Description       |
| ---------- | ---------- | ----------------- |
| `delay`    | `number`   | Delay, in seconds |
| `callback` | `function` | Callback          |

**Example**

```lua
Delay(0.5, function()
    print('Print after 0.5 seconds')
end)
```

***

## \_\_shutdown <a href="#error" id="error"></a>

<mark style="color:blue;">**`Function`**</mark>

Special function, it's called whenever the script unloads. Isn't called in case of errors.

#### Arguments

None.

**Example**

```lua
function __shutdown()
    print('Script was unloaded successfully.')
end
```


---

# 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://lua2.fatality.win/api/global-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.
