forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionForm.js
33 lines (26 loc) · 1.13 KB
/
ActionForm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// import action form from '@minecraft/server' module;
import { ActionFormData } from "@minecraft/server-ui";
const ActionForm = new ActionFormData();
// This builder method sets the title for the modal dialog.
ActionForm.title("Action Form");
// Method that sets the body text for the modal form.
ActionForm.body("This is the body text for the modal form.");
// Adds a button to this form with an icon from a resource
ActionForm.button("button icon", "textures/blocks/bedrock");
// get player object from world object in '@minecraft/server' module
import { world } from "@minecraft/server";
const player = [...world.getPlayers()][0];
ActionForm.show(player)
// This method returns a promise that resolves when the form has a response.
.then(function (formResponse) {
// The form response is an object with the following properties:
// canceled: boolean
// selection: number
const { canceled, selection } = formResponse;
console.warn(`canceled: ${canceled}`);
console.warn(`selection: ${selection}`);
})
// This method executes when an error in the promise function occurs.
.catch(function (error) {
console.error(error);
});