forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.ts
More file actions
56 lines (40 loc) · 1.91 KB
/
tests.ts
File metadata and controls
56 lines (40 loc) · 1.91 KB
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
50
51
52
53
54
55
56
import { world, Player } from "@minecraft/server";
import { ModalFormBuilder } from "./index";
// Create a new instance of ModalFormBuilder
let form = new ModalFormBuilder();
// Add a dropdown menu to the form
form.dropdown("Choose an option", ["Option 1", "Option 2", "Option 3"], 0);
// Add a toggle switch to the form
form.toggle("Toggle option", true);
// Add a slider to the form
form.slider("Slider option", 0, 10, 1, 5);
// Add a text field to the form
form.textField("Text field option", "Type something here...", "Default value");
// Set the title of the form using a string
form.title("My Modal Form");
// Show the form to the player and wait for a response
async function showModalForm(player: Player) {
const response = await form.show(player);
if (!response.formValues) return;
console.log(`Player ${player.name} selected option ${response.formValues[0]} and toggled option ${response.formValues[1]}`);
console.log(`Player ${player.name} selected slider value ${response.formValues[2]} and entered text "${response.formValues[3]}"`);
// Clear the form content
form.content = [];
// Add a dropdown menu to the form
form.dropdown("Choose a different option", ["Option 4", "Option 5", "Option 6"], 1);
// Add a toggle switch to the form
form.toggle("Another toggle option", false);
// Set the title of the form using a RawMessage
form.title("My Second Modal Form");
// Show the second form to the same player and wait for a response
const response2 = await form.show(player);
if (!response2.formValues) return;
console.log(`Player ${player.name} selected option ${response2.formValues[0]} and toggled option ${response2.formValues[1]}`);
}
// Listen for chat messages and show the form to the player who sent a specific message
world.beforeEvents.chatSend.subscribe(async (event) => {
const player = event.sender;
if (event.message === "show form") {
await showModalForm(player);
}
});