Play Strawberry Docs
Scripts

Java dialogs

Show dialogs with bodies, inputs and action buttons, and check each click.

Show a dialog

player.show_dialog(dialog) shows a java_dialog::Dialog: a Java player sees the dialog, a Bedrock player the same one as a form. player.as_java() returns the player's Java handle, or none for a Bedrock player, and java.clear_dialog() closes what it shows. A dialog has a type, bodies, inputs, action buttons and links.

Inputs and actions

Dialog inputs are boolean, number range, single option and text. A button with a custom action sends DialogClickActionEvent with the action id and an optional payload. DialogShowEvent and DialogClearEvent can be cancelled.

Please note

The click action event names the player, the action id and the payload; nothing else ties it to your dialog. Use action ids under your own namespace, check the payload's size and content, and check the player's current state before you change anything.

dialog_values::read_click_values(bytes) reads the values of a click by key (text, bool, float), so you do not parse the bytes yourself. A malformed payload is an error.

Longer text fields and button images

player.show_dialog_with(dialog, extras) takes what the dialog itself has no field for:

  • text_max_lengths: how many characters a text field accepts, 1 to 2048, for the input at that index. A field you do not list keeps the default of 32.
  • button_images: an image on a button of a Bedrock button form, as a texture path or an https address of at most 512 characters. Java clients show no image.

A refused entry (an index with no such input or button, a length out of range, an image that is too long) answers an error that says why, and nothing is shown.

On Bedrock

  • A notice or a multi-action dialog is a button form, a confirmation a form with two buttons, and a dialog with inputs a form of fields.
  • Button tooltips and widths, items in the body and the after-action have no form equivalent.
  • A server-links or dialog-list dialog is not shown to a Bedrock player.

The extension event "dialog-closed" (DIALOG_CLOSED in the SDK) tells the script that showed a dialog that a Bedrock player closed the form without answering. It goes to that script only, cannot be cancelled, and does not fire when the dialog was replaced, cleared or answered. A Java player pressing Escape sends the server nothing, so there is no event for it.

Your menu under a key of the client

A vanilla Java client (1.21.6 and later) has a quick actions key (G unless the player changed it) and room for extra buttons in its pause menu. java_dialog::set_key_dialogs(vec![KeyDialog { name, dialog, quick_actions, pause_screen }]) puts your own dialogs there, with no mod and no resource pack.

  • dialog is the same Dialog you show with show_dialog, and a click reaches your script the same way, as DialogClickActionEvent with the action's id.
  • Call it in on_load, at every start. The client learns these dialogs only while it joins, so they are fixed once the server takes players, and a later call is refused with the reason.
  • When several dialogs are under the key (from your script or from others), the client shows a list and names each by its external_title.
  • A script keeps at most 16 dialogs there, and a new call replaces your earlier list. A dialog with a click id in the server's own strawberry: namespace is refused.

Client support

Dialogs are a feature of current Java clients. Check the player's version (java.get_version()) and give older clients another way, such as an inventory menu.

On this page