> For the complete documentation index, see [llms.txt](https://fehdead.gitbook.io/npc-kit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/setmesmacro.md).

# npc.setmesmacro

```lua
npc.setmesmacro(slot, macro, kind, value)
```

|                         |                                   |
| ----------------------- | --------------------------------- |
| id                      | `0x01A8`                          |
| arguments               | 4: Int, Int, Int, Int             |
| in NPC Kit              | yes                               |
| measured from a kit NPC | returns                           |
| vanilla scripts         | 2385 calls in 180 of 1114 scripts |

## What it does

Sets macro `n` of window `slot`: a value its text shows where the text names that macro (a number, an item's name, a count).

## Arguments

### `slot` (Int)

The window slot, 0 to 7.

### `macro` (Int)

The macro number, 0 to 31.

### `kind` (Int)

What the value is: `0` a number, `1` and `2` the name of an item or other id, more kinds above.

### `value` (Int)

The number, or the id the kind names. Vanilla passes story counters, item counts (`haveitem(...)`), prices and item ids.

## Timing

Returns at once.

## In NPC Kit

**Build the text in Lua instead**: read the value with `npc.lua(npc.haveitem(id), fn)` (or any result) and put it in the `body` string. `dialog.*` windows also take a `macro` field and `{macro:...}` tags (`references/dialog.md`, Text, `references/text-tags.md`).

## Used with

* [haveitem](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/haveitem.md), [havegill](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/havegill.md): values to show.

## Example

The kit form of vanilla's `setmesmacro(0, 0, 0, haveitem(id))` + a line that shows the count: read the value with `npc.lua`, build the string in Lua.

```lua
local potions = [[
You carry only %d potions with you? Not enough!
Out there you'll need many more than that, friend.
]]

talk = function()
    talkOpen();
    npc.haveitem(0x0000);                     -- Potion
    npc.lua(function(handle, count)           -- count = haveitem's result
        if not dialog.amese.open {
                speaker = "NPCKit 0020",
                body = potions:format(count),
                queue = true,
                onClose = function() handle.finish() end,
                onError = function() handle.finish() end
            } then
            handle.finish()
        end
    end);
    talkClose();
end,
```

`npc.lua(npc.haveitem(0x0000), function(handle, count) ... end)` is the same in one line.
