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); } }); } }
if (players.length >= 1) { constform = newActionFormData() .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; } }); } }
Example: minigames.js
import { world } from"@minecraft/server"; import { ActionFormData } from"@minecraft/server-ui"; constform = newActionFormData(); form.title("Minigames"); form.body("Choose the games"); form.button("Spleef", "textures/items/diamond_shovel"); form.button("Murder Mystery", "textures/items/iron_sword"); form.button("Bedwars", "textures/minigames/bedwars.png"); for (constplayerofworld.getAllPlayers()) { form.show(player).then((response) => { if (response.canceled) { player.sendMessage("Canceled due to " + response.cancelationReason); } if (response.selection == 0) { player.sendMessage("You have selected Spleef"); } if (response.selection == 1) { player.sendMessage("You have selected Murder Mystery"); } if (response.selection == 2) { player.sendMessage("You have selected Bedwars"); } return; }); // show player the form }
Builds a simple player form with buttons that let the player take action.
Example: showActionForm.ts
Example: showFavoriteMonth.ts
Example: minigames.js