> For the complete documentation index, see [llms.txt](https://0x29a.gitbook.io/0x29a-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0x29a.gitbook.io/0x29a-docs/introduction/first-script.md).

# Your first script

A simple script that draws a HUD and reacts to a hotkey:

```lua
-- Script state
local hud_enabled = true

-- INSERT already opens the overlay menu — we use F5 for our own toggle.
bind(input.KEY.F5, function()
    hud_enabled = not hud_enabled
end)

-- Runs once per frame, whenever the overlay is up.
_29a.on_frame(function()
    if not hud_enabled then return end

    local w, h = ui.get_io_display_size()
    local fps  = ui.framerate()

    render.text(12, 12, color(1, 1, 1, 1), string.format("FPS: %.0f", fps))
    render.rect(8, 8, 140, 22, color(0.5, 0.3, 1, 0.5))
end)

print("script loaded — F5 toggles the HUD")
```

Key points:

* `_29a.on_frame(fn)` registers a callback that runs every frame — this is how most scripts draw a HUD/ESP. See [Lifecycle](/0x29a-docs/introduction/lifecycle.md).
* `bind(vk, fn)` binds a key (`input.KEY.*`) to a function, with edge detection (fires once per press, not on repeat). See [Hotkeys](/0x29a-docs/introduction/hotkeys.md).
* `render.*` draws straight on screen in screen coordinates — no need to manage an ImGui window for a simple HUD.
* `print()` goes to the overlay's console (the **Console** tab).

## An example reading memory

```lua
local m = mem.module(nil)              -- the process's main module
print(string.format("base: 0x%X  size: 0x%X", m.base, m.size))

local hp_addr = sig.scan("48 8B 05 ? ? ? ? 8B 88 ? ? ? ?")
if hp_addr then
    local hp = mem.read_i32(mem.deref(hp_addr, 3))
    print("current hp:", hp)
else
    print("signature not found — did the game update?")
end
```

`sig.scan` searches for a byte pattern (with `?` as a wildcard) and returns the address where it shows up — the backbone of pretty much every script that survives game updates. See the full reference in [sig](/0x29a-docs/memory-and-analysis/sig.md) and [mem](/0x29a-docs/memory-and-analysis/mem.md).


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://0x29a.gitbook.io/0x29a-docs/introduction/first-script.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
