#Help
1 messages · Page 1 of 1 (latest)
Debug Result
There are 85 errors in this [code](#1135837895794638940 message).
Please read the attached file for the result.
Debug (Stable)
ok, i can help
firstly, idk why you put the same code twice
secondly, that is a terrible way to store all the data
import { world, Player, system } from "@minecraft/server";
import { ModalFormData } from "@minecraft/server-ui";
function hotbarDetect() {
// Rest of the code...
}
function getTwoDigitNumber(value) {
// Rest of the code...
}
function hour() {
// Rest of the code...
}
function minute() {
// Rest of the code...
}
function second() {
// Rest of the code...
}
hotbarDetect();
hour();
minute();
second();
// Open UI when stick is used
world.afterEvents.itemUse.subscribe(event => {
const { source: player, itemStack } = event;
if (event.itemStack.typeId === "kc:sword_combat_menu") {
openModalTemplate(player);
}
});
// Put UI into a function
function openModalTemplate(player) {
const slots = [
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"Head-slash", "Right-shoulder-slash", "Left-shoulder-slash",
"Right-gut-slash", "Left-gut-slash", "Right-leg-slash",
"Left-Leg-slash", "Rotational-slash", "Blade-thrust"
];
const moves = ["Idle", "Step", "Back-step", "Leap"];
new ModalFormData()
.title("bSword §4|§b Combat Configurations") // Title of the form
.dropdown('Pick the number of attacks:', slots) // Dropdown 1
// Add rest of the dropdowns here...
.show(player)
.then(({ formValues }) => {
const dropdownResults = formValues.map(value => slots[value]);
if (dropdownResults[2] === "Hello") {
player.runCommand('say hello')
}
// Do something with the array of dropdown results
});
}
customise this
to get the results, use dropdownResults[dropdown number - 1]
-1 is because it starts at 0 in arrays
Debug Result
There are 3 errors in this [code](#1135837895794638940 message):
[36m<repl>.js[0m:[33m55[0m:[33m31[0m - [31merror[0m[30m TS18048: [0m'formValues' is possibly 'undefined'.
[7m55[0m const dropdownResults = formValues.map(value => slots[value]);
[7m [0m [31m ~~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m55[0m:[33m61[0m - [31merror[0m[30m TS2538: [0mType 'false' cannot be used as an index type.
[7m55[0m const dropdownResults = formValues.map(value => slots[value]);
[7m [0m [31m ~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m55[0m:[33m61[0m - [31merror[0m[30m TS2538: [0mType 'true' cannot be used as an index type.
[7m55[0m const dropdownResults = formValues.map(value => slots[value]);
[7m [0m [31m ~~~~~[0m
Debug (Stable)
Thank you
Was the hotbar detect part breaking it?
no
👍
The command section isn't working, I fixed it and broke it again 😓
whats ur error
.then(({ formValues: [dropdown] }) => {
const { formValues } = ModalFormResponse;
const dropdownResults = attacks1[dropdown];
if (dropdownResults === "1") {
player.runCommand('scoreboard players set @s attack_pattern2 2')
}
I changed it to this but it didn't work either
.then(({ formValues: [dropdown] }) => {
const dropdownResults = attacks1[dropdown];
if (dropdownResults === "1") {
player.runCommand('scoreboard players set @s attack_pattern2 2')
}
try this
Ok