[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/client](https://jsprismarine.dev/api/@jsprismarine/client/index.md) / DataDrivenScreens

# Class: DataDrivenScreens

Defined in: [client/src/DataDrivenScreens.ts:110](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/DataDrivenScreens.ts#L110)

The client's half of `@minecraft/server-ui`'s data-driven screens: the `CustomForm` and
`MessageBox` a behavior pack shows. The server sets the screen's property in the `minecraft`
data store and then opens the screen; this keeps each property's values by path, answers a
close the server asks for as a player's client does, and sends the player's clicks, writes and
dismissals. It reads both layouts the server sends: a property of maps up to protocol 2225, and
a variable per value from 2259.

Emits `show` with a [ClientScreen](https://jsprismarine.dev/api/@jsprismarine/client/index.md#clientscreen) when a screen opens, and `close` with the form id
when one closes.

## Extends

- `EventEmitter`

## Constructors

### Constructor

> **new DataDrivenScreens**(`session`, `protocolVersion`): `DataDrivenScreens`

Defined in: [client/src/DataDrivenScreens.ts:127](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/DataDrivenScreens.ts#L127)

Registers the screen handlers on the session, for the life of the session.

#### Parameters

##### session

[`ClientSession`](https://jsprismarine.dev/api/@jsprismarine/client/classes/ClientSession.md)

The session whose screens this follows and answers.

##### protocolVersion

`number`

The protocol the client speaks, which decides the data store layout.

#### Returns

`DataDrivenScreens`

#### Overrides

`EventEmitter.constructor`

## Properties

### PACKETS

> `readonly` `static` **PACKETS**: readonly \[*typeof* [`ClientboundDataStorePacket`](https://jsprismarine.dev/api/@jsprismarine/protocol/classes/ClientboundDataStorePacket.md), *typeof* [`ClientboundDataDrivenUIShowScreenPacket`](https://jsprismarine.dev/api/@jsprismarine/protocol/classes/ClientboundDataDrivenUIShowScreenPacket.md), *typeof* [`ClientboundDataDrivenUICloseScreenPacket`](https://jsprismarine.dev/api/@jsprismarine/protocol/classes/ClientboundDataDrivenUICloseScreenPacket.md)\]

Defined in: [client/src/DataDrivenScreens.ts:112](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/DataDrivenScreens.ts#L112)

The packets this reads, registered on the client's registry with the others.

## Methods

### click()

> **click**(`formId`, `path`): `Promise`\<`void`\>

Defined in: [client/src/DataDrivenScreens.ts:193](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/DataDrivenScreens.ts#L193)

Clicks a button or image by the path of its `onClick`, such as `layout[4].onClick`,
`layout[1].image_onClick` or a message box's `button1.onClick`.

#### Parameters

##### formId

`number`

##### path

`string`

#### Returns

`Promise`\<`void`\>

***

### close()

> **close**(`formId`, `reason?`): `Promise`\<`void`\>

Defined in: [client/src/DataDrivenScreens.ts:199](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/DataDrivenScreens.ts#L199)

Reports a screen closed, by default as the player dismissing it.

#### Parameters

##### formId

`number`

##### reason?

[`DataDrivenScreenClosedReason`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#datadrivenscreenclosedreason) = `DataDrivenScreenClosedReason.ClientCanceled`

#### Returns

`Promise`\<`void`\>

***

### screens()

> **screens**(): readonly [`ClientScreen`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#clientscreen)[]

Defined in: [client/src/DataDrivenScreens.ts:163](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/DataDrivenScreens.ts#L163)

The screens open now, oldest first.

#### Returns

readonly [`ClientScreen`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#clientscreen)[]

***

### write()

> **write**(`formId`, `path`, `value`): `Promise`\<`void`\>

Defined in: [client/src/DataDrivenScreens.ts:168](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/DataDrivenScreens.ts#L168)

Writes a value to one path of an open screen's property, as an input control does.

#### Parameters

##### formId

`number`

##### path

`string`

##### value

[`ScreenWriteValue`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#screenwritevalue)

#### Returns

`Promise`\<`void`\>
