#How to fix custom gui menu

1 messages · Page 1 of 1 (latest)

polar panther
#

I only know how to create a button, but I don't know how to insert a command into it.

sharp zephyr
#

#1067535382285135923

sharp zephyr
polar panther
#

Do you have a sample script?

sharp zephyr
# polar panther 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

polar panther
#

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?

sharp zephyr
#

and then do something similar to how i did in my example

polar panther
sharp zephyr
polar panther
polar panther
polar panther
#

@sharp zephyr help me pls 🥲