ActionFormData Class
Builds a simple player form with buttons that let the player take action.
Examples
actionFormAskFavoriteMonth.ts
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.');
}
});
}
Methods
constructor
new ActionFormData()
Creates a new modal form builder.
Returns ActionFormData
body
body(bodyText: minecraftserver.RawMessage | string): ActionFormData
Method that sets the body text for the modal form.
Parameters
- bodyText: @minecraft/server.RawMessage | string
Returns ActionFormData
button
button(text: minecraftserver.RawMessage | string, iconPath?: string): ActionFormData
Adds a button to this form with an icon from a resource pack.
Parameters
- text: @minecraft/server.RawMessage | string
- iconPath?: string =
null
Returns ActionFormData
show
show(player: minecraftserver.Player): Promise<ActionFormResponse>
Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog.
Parameters
player: @minecraft/server.Player
Player to show this dialog to.
Returns Promise<ActionFormResponse>
Important
This function can't be called in read-only mode.
Warning
This function can throw errors.
title
title(titleText: minecraftserver.RawMessage | string): ActionFormData
This builder method sets the title for the modal dialog.
Parameters
- titleText: @minecraft/server.RawMessage | string
Returns ActionFormData
Examples
actionFormAskFavoriteMonth.ts
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.');
}
});
}
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for