> For the complete documentation index, see [llms.txt](https://docs.perfectcs2.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.perfectcs2.com/documentacao/api/storage.md).

# storage

Salvar dados entre sessões.

`storage` guarda valores que continuam lá na próxima vez que o script rodar, mesmo depois de fechar o jogo. Cada script tem o seu próprio armazenamento.

```lua
local kills = storage.get("kills", 0)

events.on("player_death", function(e)
    if e.attacker == entities.local_player().index then
        kills = kills + 1
        storage.set("kills", kills)
    end
end)
```

| Função                        |                                                                       |
| ----------------------------- | --------------------------------------------------------------------- |
| `storage.get(key, [default])` | Valor salvo, ou `default` se não houver                               |
| `storage.set(key, value)`     | Salva. `value` pode ser `boolean`, `number` ou `string`; `nil` apaga. |
| `storage.remove(key)`         | Apaga uma chave                                                       |
| `storage.keys()`              | Tabela com todas as chaves                                            |
| `storage.clear()`             | Apaga tudo deste script                                               |

* Os valores voltam com o mesmo tipo: um inteiro salvo continua inteiro (`2`, não `2.0`).
* Os dados ficam em `scripts\data\<nome-do-arquivo>.dat`.
* Eles são gravados cerca de 1 segundo depois da última mudança e também quando o script para.
* Para guardar uma tabela, transforme em texto. Por exemplo, uma posição: `storage.set("pos", x .. "," .. y)`, lida depois com [`utils.split`](/documentacao/tipos/utils.md).

{% hint style="warning" %}
As opções criadas com `ui.*` **não** são salvas sozinhas: ao carregar, voltam ao padrão do código. Para lembrar a escolha da pessoa, salve no callback da opção e use o valor salvo como padrão:

```lua
local fov = ui.slider("FOV", "", 1, 10, storage.get("fov", 4))
fov:callback(function(option) storage.set("fov", option:get()) end)
```

{% 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.perfectcs2.com/documentacao/api/storage.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.
