Script API - v26.60
    Preparing search index...

    Class MessageFormResponse

    Returns data about the player results from a modal message form.

    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;
    });
    }
    import { world, DimensionLocation } from '@minecraft/server';
    import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';

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

    const messageForm = new MessageFormData()
    .title({ translate: 'permissions.removeplayer' })
    .body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] })
    .button1('Player 1')
    .button2('Player 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 ? 'Player 1' : 'Player 2'}`);
    })
    .catch((error: Error) => {
    log('Failed to show form: ' + error);
    return -1;
    });
    }
    export class MessageFormResponse extends FormResponse {
    private constructor();
    readonly selection?: number;
    }

    Hierarchy (View Summary)

    Index
    cancelationReason?: FormCancelationReason

    Contains additional details as to why a form was canceled.

    This property can't be read in early-execution mode.

    import { Player, system } from "@minecraft/server";
    import { ActionFormData, FormCancelationReason } from "@minecraft/server-ui";

    // Run `/scriptevent example:whyshopclosed` in chat to open the form.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:whyshopclosed" || !(sourceEntity instanceof Player)) return;

    const form = new ActionFormData();
    form.title("Item Shop");
    form.button("Buy Apple");

    form.show(sourceEntity).then((response) => {
    if (!response.canceled) {
    sourceEntity.sendMessage("Purchased an apple.");
    return;
    }

    // `cancelationReason` explains why the form closed without a selection.
    if (response.cancelationReason === FormCancelationReason.UserBusy) {
    sourceEntity.sendMessage("Could not open shop because you were busy.");
    } else if (response.cancelationReason === FormCancelationReason.UserClosed) {
    sourceEntity.sendMessage("You dismissed the shop menu.");
    }
    });
    });
    canceled: boolean

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

    This property can't be read in early-execution mode.

    import { Player, system } from "@minecraft/server";
    import { ActionFormData } from "@minecraft/server-ui";

    // Run `/scriptevent example:questboard` in chat to open the form.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:questboard" || !(sourceEntity instanceof Player)) return;

    const form = new ActionFormData();
    form.title("Quest Board");
    form.button("Accept Quest");

    form.show(sourceEntity).then((response) => {
    // `canceled` is true when the player closed the dialog without choosing an action.
    if (response.canceled) {
    sourceEntity.sendMessage("You closed the quest board without accepting.");
    return;
    }

    sourceEntity.sendMessage("You accepted the quest.");
    });
    });
    selection?: number

    Returns the index of the button that was pushed.

    This property can't be read in early-execution mode.

    import { Player, system } from "@minecraft/server";
    import { MessageFormData } from "@minecraft/server-ui";

    // Run `/scriptevent example:pickdifficulty` in chat to open the form.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:pickdifficulty" || !(sourceEntity instanceof Player)) return;

    const form = new MessageFormData();
    form.title("Difficulty Prompt");
    form.body("Increase monster spawn rate for extra loot?");
    form.button1("Yes, Increase");
    form.button2("No, Keep Normal");

    form.show(sourceEntity).then((response) => {
    if (response.canceled) return;

    // `selection` is 0 when the player presses `button1` and 1 for `button2`.
    if (response.selection === 0) {
    sourceEntity.sendMessage("Harder difficulty selected.");
    } else {
    sourceEntity.sendMessage("Normal difficulty kept.");
    }
    });
    });