#how do i make this work?
1 messages · Page 1 of 1 (latest)
js, not json, and thats a file, but whatever
world.beforeEvents.itemUse.subscribe(async (eventData) => {
const player = eventData.source;
const itemUsed = eventData.itemStack;
suvUi.textField("Enter a secret code", "Code", "")
server.system.run(async () => {
if (itemUsed.typeId == "prp:customize1") {
const operationResult = await suvUi.show(player);
const [text] = result.formValues;
switch (operationResult.selection) {
case 0:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
case 1:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
case 2:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
case 3:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
case 4:
break;
}
switch (text) {
case '1234':
player.sendMessage('§l§cStill on WIP')
break;
}
}
})
});
what is the problem
i want to detect an specific text in the textfield and make an "event"
i want to detect when i type 1234 inside the form
but the textfield doesn't works
where's your suvUi? why isnt it not initiated
do you want me to send you all the code?
no, i want you to analyze your problem, ill help you solve it by your own
have you initiated a modalform called suvUi?
that is my code, the problem is that the textfield is not working, not event outside of the world.beforeEvents and idk why
and when i use the item it says this
actionform data has no textfield
do i change action to modal?
import * as server from '@minecraft/server'
import { ActionFormData, ModalFormData } from "@minecraft/server-ui";
const world = server.world
const option = [`Hats`,`Grabpacks`,`Hands`,`Feet`]
const suvUi = new ModalFormData();
suvUi.title(`Survivor Customisation`)
suvUi.dropdown(`Select:`,option,0)
suvUi.textField("Enter a secret code", "Code", "")
world.beforeEvents.itemUse.subscribe((eventData) => {
const player = eventData.source;
const itemUsed = eventData.itemStack;
server.system.run(() => {
if (itemUsed.typeId == "prp:customize1") {
suvUi.show(player).then((response) => {
const [selection,text] = response.formValues;
switch (selection) {
case 0:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
case 1:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
case 2:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
case 3:
player.runCommandAsync(`tellraw @s {"rawtext":[{"text":"§l§cStill on WIP"}]}`)
break;
}
switch (text) {
case '1234':
player.sendMessage('§l§cStill on WIP')
break;
}
})
}
})
});
There are 2 errors in this [code](#1118556819401482320 message):
[36m<repl>.js[0m:[33m15[0m:[33m24[0m - [31merror[0m[30m TS2345: [0mArgument of type 'Entity' is not assignable to parameter of type 'Player'.
Type 'Entity' is missing the following properties from type 'Player': level, name, onScreenDisplay, selectedSlot, and 16 more.
[7m15[0m suvUi.show(player).then((response) => {
[7m [0m [31m ~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m33[0m:[33m28[0m - [31merror[0m[30m TS2339: [0mProperty 'sendMessage' does not exist on type 'Entity'.
[7m33[0m player.sendMessage('§l§cStill on WIP')
[7m [0m [31m ~~~~~~~~~~~[0m
do i copy this code?