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

    Class ActionFormResponse

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

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

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

    if (playerList.length >= 1) {
    const form = new ActionFormData()
    .title('Test Title')
    .body('Body text here!')
    .button('btn 1')
    .button('btn 2')
    .button('btn 3')
    .button('btn 4')
    .button('btn 5');

    form.show(playerList[0]).then((result: ActionFormResponse) => {
    if (result.canceled) {
    log('Player exited out of the dialog. Note that if the chat window is up, dialogs are automatically canceled.');
    return -1;
    } else {
    log('Your result was: ' + result.selection);
    }
    });
    }
    }
    import { world, DimensionLocation } from '@minecraft/server';
    import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui';

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

    if (players.length >= 1) {
    const form = new ActionFormData()
    .title('Months')
    .body('Choose your favorite month!')
    .button('January')
    .button('February')
    .button('March')
    .button('April')
    .button('May');

    form.show(players[0]).then((response: ActionFormResponse) => {
    if (response.selection === 3) {
    log('I like April too!');
    return -1;
    }
    });
    }
    }
    export class ActionFormResponse 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 { ActionFormData } from "@minecraft/server-ui";

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

    const form = new ActionFormData();
    form.title("Choose Starter Kit");
    form.button("Warrior");
    form.button("Archer");

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

    // `selection` holds the index of the button the player chose.
    if (response.selection === 0) {
    sourceEntity.sendMessage("You picked the Warrior kit.");
    } else if (response.selection === 1) {
    sourceEntity.sendMessage("You picked the Archer kit.");
    }
    });
    });