> 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/messync.md).

# npc.messync

```lua
npc.messync(slot, close)
```

|                         |                                                   |
| ----------------------- | ------------------------------------------------- |
| id                      | `0x0011`                                          |
| arguments               | 2: Int, Int                                       |
| in NPC Kit              | yes                                               |
| measured from a kit NPC | waits: holds the script until its condition holds |
| vanilla scripts         | 20191 calls in 626 of 1114 scripts                |

## What it does

Holds the script until message window `slot` is done: the player has read the line and closed it.

## Arguments

### `slot` (Int)

The window slot (0 to 7) to wait on, the one the `amese` / `ames` / `aask` opened. Vanilla: `0` most of the time, then `1`, `6`, `2`, `5`.

### `close` (Int)

Vanilla passes `1` in all but 138 of about 20,000 calls. What `0` changes is not confirmed here.

## Timing

Waits, checking once per frame, until the window has finished closing. With no window open on that slot it returns at once: a kit NPC measured 0 frames for `messync(0, 1)`.

## In NPC Kit

Only meaningful after a VM window call (`amese`, `ames`, `aask`...), which in the kit have no text of yours (see [amese](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/amese.md)). For `dialog.*` windows, the wait is `npc.lua` until `handle.finish()`, called from the window's `onClose`.

## Used with

* [amese](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/amese.md), [aaske](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/aaske.md), [ames](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/ames.md): the window it waits for.
* [setkutipakustatus](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/setkutipakustatus.md) / [setunazukistatus](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/setunazukistatus.md): on before, off after.

## Example

In the kit the wait for a window is `npc.lua` itself: the script stays there until the window's `onClose` calls `handle.finish()`. The lines after it run once the player has closed the window.

```lua
local roads = [[
The roads are not safe at night, not anymore.
Stay inside the walls until the sun is back up.
]]

talk = function()
    talkOpen();
    npc.lua(function(handle)                 -- the kit's messync
        if not dialog.amese.open {
                speaker = "NPCKit 0020",
                body = roads,
                queue = true,
                onClose = function() handle.finish() end,
                onError = function() handle.finish() end
            } then
            handle.finish()
        end
    end);
    talkClose();                             -- runs after the window closed
end,
```

## Pitfalls

* In a talk it holds the player until the window closes.
