Skip to main content

Class: ActionFormData

Builds a simple player form with buttons that let the player take action.

Example

import { Player } from '@minecraft/server';
import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui';

function askFavoriteMonth(player: Player) {
const form = new ActionFormData()
.title('Months')
.body('Choose your favorite month!')
.button('January')
.button('February')
.button('March')
.button('April')
.button('May');

form.show(player).then((response: ActionFormResponse) => {
if (response.selection === 3) {
player.sendMessage('I like April too!');
} else {
player.sendMessage('Nah, April is the best.');
}
});
}

Constructors

new ActionFormData()

new ActionFormData(): ActionFormData

Returns

ActionFormData

Methods

body()

body(bodyText): ActionFormData

Parameters

ParameterType
bodyTextstring | RawMessage

Returns

ActionFormData

Remarks

Method that sets the body text for the modal form.


button()

button(text, iconPath?): ActionFormData

Parameters

ParameterType
textstring | RawMessage
iconPath?string

Returns

ActionFormData

Remarks

Adds a button to this form with an icon from a resource pack.


show()

show(player): Promise ↗️ <ActionFormResponse>

Parameters

ParameterTypeDescription
playerPlayerPlayer to show this dialog to.

Returns

Promise ↗️ <ActionFormResponse>

Remarks

Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog.

This function can't be called in read-only mode.

Throws

This function can throw errors.


title()

title(titleText): ActionFormData

Parameters

ParameterType
titleTextstring | RawMessage

Returns

ActionFormData

Remarks

This builder method sets the title for the modal dialog.