# Protocol: ui

The `ui` commands a program sends to a running game, as the engine describes them: what each takes, what it answers and what it does. Back to [all commands](../protocol-commands.md).

## ui.tree

`ui.tree {} -> {step: integer, focus: text, modal: text, nodes: [record]}` · read, read-only

Reads the game's interface as it is laid out now: every node's box, what it is, its value and which has the focus. What a client reads to see a menu without a picture, and to know where to press.

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `focus` | text | The entity that has the focus, by its name when it has one and its id otherwise. null: none has. |
| `modal` | text | The shown modal node that has the interface, named the same way: only the nodes in it can be used. null: none is shown. |
| `nodes` | [record] | One {entity, name, parent, x, y, w, h, shown, kind, value, off, locked, text} per entity with a Node, in entity order. parent is the id of the node it is in, or null. x and y are the middle of its box and w and h its size, in frame units for a node with Screen. shown is false for a hidden node and everything in one. kind is "box", "button", "slider", "choice", "toggle" or "bar"; value is a slider's or a bar's value, a choice's index, whether a toggle is on, and null for the rest. off is true for a button that is off, locked for a node that takes the focus and refuses to be used. text is what the node reads: its own Text, or that of the entity its label names; null when it has neither. A game with no interface has no nodes. |

## ui.focus

`ui.focus {entity: text} -> {step: integer, focus: text}` · write

Gives a node the interface's focus, as a script's ui.focus does: at once, with no step. A node that cannot have it now (it is hidden, off, not something a person uses, or shut out by a modal node) is not given it, and the answer says where the focus is.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `entity` | text | The entity's scene name, or its id as world.entities gives it, like "e3.0". |

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `focus` | text | The entity that has the focus now, by its name when it has one and its id otherwise. null: none has. |
