> 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/comecando/primeiro-script.md).

# Primeiro script

Do arquivo vazio a uma opção no menu e um texto na tela.

## 1. Criar o arquivo

Na aba **Scripts**, clique em **Novo script**, o ícone de arquivo com `+` ao lado da busca. O Perfect cria `new_script.lua` na pasta de scripts e abre o editor com este modelo:

```lua
-- @name New Script
-- @author your_name
-- @version 1.0
-- @description What this script does.

ui.group("Options", "What this script changes")
local enabled = ui.toggle("Enabled", "Turn the script on", true)

print("Hello from Lua!")
```

Também dá para criar o arquivo em qualquer editor, dentro de `Documentos\Perfect\Scripts`. Ele aparece na lista sozinho.

## 2. Escrever

Troque o conteúdo por um script que desenha a hora quando a opção está ligada:

```lua
-- @name Clock
-- @author your_name
-- @description Shows the time in the corner of the screen.

ui.group("Clock", "Time in the corner of the screen")
local show = ui.toggle("Show", "Turns the clock on", true, color(255, 255, 255))
local size = ui.slider_int("Size", "Text size", 12, 32, 16, "%d px")

callbacks.add("draw", function()
    local on, clr = show:get()
    if not on then return end
    local width = render.screen_size()
    render.text(width - 20, 20, os.date("%H:%M:%S"), clr, {
        size = size:get(), font = "bold", align = "right", shadow = true,
    })
end)
```

## 3. Rodar

* No editor, **Salvar e rodar** salva o arquivo e liga o script. Se ele já estiver rodando, o botão vira **Salvar e recarregar**.
* Na lista, o switch ao lado do script faz o mesmo.
* As opções criadas com `ui.*` aparecem na aba **Opções**, à direita da lista.

## 4. Ver o que aconteceu

* A aba **Console** mostra o que o script escreveu com `print` e `warn`, e os erros.
* Quando há um erro, o script para, a lista mostra a mensagem em vermelho e o editor marca a linha. Passe o mouse na linha marcada para ver a mensagem.

```
clock.lua:9: attempt to index a nil value (global 'shwo')
```

## 5. Carregar sozinho

O switch **Auto** no card do script faz ele carregar sempre que o menu abrir. A escolha fica salva em `autoload.txt`, na pasta de scripts.

## Próximos passos

* [Cabeçalho do arquivo](/comecando/cabecalho.md): nome, autor e descrição na lista.
* [Ciclo de vida](/comecando/ciclo-de-vida.md): quando cada parte do script roda.
* [ui](/documentacao/api/ui.md): todos os tipos de opção.
* [render](/documentacao/api/render.md): tudo o que dá para desenhar.


---

# 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/comecando/primeiro-script.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.
