For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server-ui/classes/MessageFormResponse.md.

Class: MessageFormResponse

Beta

Returns data about the player results from a modal message form. 返回关于玩家在模态消息表单中操作结果的数据。

Examples

showBasicMessageForm.ts
showTranslatedMessageForm.ts
import { world, DimensionLocation } from '@minecraft/server';
import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';

function showBasicMessageForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  const messageForm = new MessageFormData()
    .title('Message Form Example')
    .body('This shows a simple example using §o§7MessageFormData§r.')
    .button1('Button 1')
    .button2('Button 2');

  messageForm
    .show(players[0])
    .then((formData: MessageFormResponse) => {
      // player canceled the form, or another dialog was up and open.
      if (formData.canceled || formData.selection === undefined) {
        return;
      }

      log(`You selected ${formData.selection === 0 ? 'Button 1' : 'Button 2'}`);
    })
    .catch((error: Error) => {
      log('Failed to show form: ' + error);
      return -1;
    });
}

Extends

Properties

cancelationReason?

readonly optional cancelationReason?: FormCancelationReason

Beta

Remarks

包含关于表单为何被取消的附加详细信息。

Contains additional details as to why a form was canceled.

Inherited from

FormResponse.cancelationReason


canceled

readonly canceled: boolean

Beta

Remarks

如果为 true,则表示表单已被玩家取消(例如,他们点击了弹窗的 X 关闭按钮)。

If true, the form was canceled by the player (e.g., they selected the pop-up X close button).

Inherited from

FormResponse.canceled


selection?

readonly optional selection?: number

Beta

Remarks

Returns the index of the button that was pushed. 返回被按下的按钮的索引。