#How to fix custom gui menu
1 messages · Page 1 of 1 (latest)
there's nothing to fix, you detect the selection with script api and then run your command.
#1067535382285135923
I don't know what to do.
selection as in the buttons
Do you have a sample script?
form.button("first button") // 0
form.button("second button") // 1
form.button("third button") // 2
// and so on
form.show(player).then(d => {
const sel = d.selection;
switch (sel) {
case 0:
player.runCommandAsync("say first button")
break;
case 1:
player.runCommandAsync("say second button")
break;
case 2:
player.runCommandAsync("third and final button")
break;
}
});
and in json ui we call the selection the collection index
Mine is like this.
import { world } from "@minecraft/server"
import { ActionFormData } from "@minecraft/server-ui"
const ui = new ActionFormData()
.title("SELECT CLASS")
.body("")
.button("Rifleman", "textures/class/icon_Rifleman")
.button("Assault")
.button("Medic")
.button("Sniper")
.button("Manchine gunner", "textures/class/icon_Manchin Gunner")
.button("Commander");
world.afterEvents.itemUse.subscribe((event) => {
const { source, itemStack } = event
switch (itemStack.typeId) {
case "minecraft:compass": ui.show(source); break;
}
})
How to fix it?
you're showing it to the source, so add a .then because it works like a promise
and then do something similar to how i did in my example
I don't understand anything 🥹
if you didn't, you wouldn't have been able to make that gui in the first place
Where do I need to fix this? 😓
Can you write it for me? I tried but it didn't work.
@sharp zephyr help me pls 🥲