PrivateconstructorOptional ReadonlycancelationThis 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.");
}
});
});
ReadonlycanceledIf 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.");
});
});
Optional ReadonlyformThis property can't be read in early-execution mode.
import { Player, system } from "@minecraft/server";
import { ModalFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:saveplayersettings` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:saveplayersettings" || !(sourceEntity instanceof Player)) return;
const form = new ModalFormData();
form.title("Player Settings");
form.textField("Nickname", "Your name");
form.toggle("Show Rank", { defaultValue: true });
form.show(sourceEntity).then((response) => {
if (response.canceled || !response.formValues) return;
// `formValues` contains the values in the order controls were added.
const [nickname, showRank] = response.formValues;
sourceEntity.sendMessage(`Saved: Nickname = ${nickname}, Show Rank = ${showRank}`);
});
});
Returns data about player responses to a modal form.
Example: showBasicModalForm.ts
Source