forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModalForm.js
49 lines (39 loc) · 1.43 KB
/
ModalForm.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// import modal form from '@minecraft/server-ui' module;
import { ModalFormData } from "@minecraft/server-ui";
const ModalForm = new ModalFormData();
// Adds a dropdown with choices to the form.
const choices = ["choice 1", "choice 2", "choice 3"];
ModalForm.dropdown("dropdown", choices);
/**
* @remarks
* Adds a numeric slider to the form.
* @param {string} label
* @param {number} minimumValue
* @param {number} maximumValue
* @param {number} valueStep
* @param {number} defaultValue
*/
ModalForm.slider("slider", 0, 100, 50);
// Adds a textbox to the form.
ModalForm.textField("text field", "text");
// This builder method sets the title for the modal dialog.
ModalForm.title("Modal Form");
// Adds a toggle checkbox button to the form.
ModalForm.toggle("toggle");
// get player object from world object in '@minecraft/server' module
import { world } from "@minecraft/server";
const player = [...world.getPlayers()][0];
ModalForm.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
// formValues: any[]
const { canceled, formValues } = formResponse;
console.warn(`canceled: ${canceled}`);
console.warn(`formValues: ${formValues}`);
})
// This method executes when an error in the promise function occurs.
.catch(function (error) {
console.error(error);
});