> For the complete documentation index, see [llms.txt](https://docs.gamesense.biz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gamesense.biz/pt-br/api-reference/callbacks.md).

# Callbacks

Eventos on\_update e on\_paint e registro de callbacks.

Callbacks executam funções Lua quando determinados eventos ocorrem.

## Eventos

| Evento      | Descrição                                                                                       |
| ----------- | ----------------------------------------------------------------------------------------------- |
| `on_update` | Chamado quando o estado do jogo é atualizado. Executado na thread do jogo, com acesso a IL2CPP. |
| `on_paint`  | Chamado durante a renderização de cada quadro. Destinado à lógica relacionada à renderização.   |

## register\_callback

```lua
register_callback(event: string, callback: function)
```

Registra uma função para determinado evento.

| Parâmetro  | Tipo       | Descrição                               |
| ---------- | ---------- | --------------------------------------- |
| `event`    | `string`   | `"on_update"` ou `"on_paint"`           |
| `callback` | `function` | Função executada quando o evento ocorre |

**Exemplo**

```lua
local counter = menu.label("Frames: 0")
local frames = 0

register_callback("on_paint", function()
    frames = frames + 1
    counter:set("Frames: " .. frames)
end)
```

Um mesmo evento pode ter vários callbacks registrados.

## unregister\_callback

```lua
unregister_callback(event: string)
```

Remove **todos** os callbacks do evento especificado registrados pelo script atual.

| Parâmetro | Tipo     | Descrição      |
| --------- | -------- | -------------- |
| `event`   | `string` | Nome do evento |

```lua
unregister_callback("on_paint")
```

{% hint style="warning" %}
As operações IL2CPP devem ser executadas na thread do jogo, dentro de `on_update`.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gamesense.biz/pt-br/api-reference/callbacks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
