how could i make something like this to work? js export function testForm(source) { const form = new ActionFormData(); form.title(`§2\n§8Chest`); form.body(``); const numberData = { 5: { texture: "textures/items/apple", command: "/give @p apple 1", }, 31: { texture: "textures/items/apple", command: "/say Button 31 clicked", }, 52: { texture: "textures/items/apple", command: "/teleport @p 0 64 0", }, 15: { texture: "textures/items/apple", command: "/summon creeper", }, }; const numbers = Array.from({ length: 63 }, (_, index) => index); numbers.forEach((buttonNumber) => { const buttonData = numberData[buttonNumber]; const buttonTexture = buttonData ? buttonData.texture : undefined; form.button(`${buttonNumber}`, buttonTexture); }); form.show(source).then((result) => { const buttonCommand = buttonData ? buttonData.command : undefined; source.runCommandAsync(`${buttonCommand}`) }); } the texture stuff works but i cant get the teleport to, im trying to assign the command that button runs based on the number of it.
#form stuff
1 messages · Page 1 of 1 (latest)
and id also like to make the command universal
so like
the command: could even be a function from js
or an in game command
nvm i got it all lol, js export function testForm(source) { const form = new ActionFormData(); form.title(`§2\n§8Chest`); form.body(``); const numberData = { 5: { texture: "textures/items/apple", command: source.runCommandAsync(`/give @p apple 1`), }, 31: { texture: "textures/items/apple", command: source.runCommandAsync(`/give @p apple 1`), }, 52: { texture: "textures/items/apple", command: source.runCommandAsync(`/give @p apple 1`), }, 15: { texture: "textures/items/apple", command: source.runCommandAsync(`/give @p apple 1`), }, }; const numbers = Array.from({ length: 63 }, (_, index) => index); numbers.forEach((buttonNumber) => { const buttonData = numberData[buttonNumber]; const buttonTexture = buttonData ? buttonData.texture : undefined; form.button(`${buttonNumber}`, buttonTexture); }); form.show(source).then((result) => { const buttonNumber = result.selection; const buttonData = numberData[buttonNumber]; if (buttonData && buttonData.command) { eval(buttonData.command); } }); }
actually wait
does anyone know why the function above runs ALL button commands whenever you click any button defined?
but, this function works perfectly fine. js export function testForm(source) { const form = new ActionFormData(); form.title(`§2\n§8Chest`); form.body(``); const numberData = { 5: { texture: "textures/items/apple", command: "source.sendMessage(`hi`)", }, 31: { texture: "textures/items/apple", command: "source.runCommandAsync(`give @p apple 1`)", }, 52: { texture: "textures/items/apple", command: "source.runCommandAsync(`give @p apple 1`)", }, 15: { texture: "textures/items/apple", command: "source.runCommandAsync(`give @p apple 1`)", }, }; const numbers = Array.from({ length: 63 }, (_, index) => index); numbers.forEach((buttonNumber) => { const buttonData = numberData[buttonNumber]; const buttonTexture = buttonData ? buttonData.texture : undefined; form.button(`${buttonNumber}`, buttonTexture); }); form.show(source).then((result) => { const buttonNumber = result.selection; const buttonData = numberData[buttonNumber]; if (buttonData && buttonData.command) { eval(buttonData.command); } }); }
when they are stringified
someone??
use:
const form = new ActionFormData();
const numberData = [
0 = {
texture: "textures/items/apple",
command: "tellraw @s {\"rawtext\":[{\"text\":\"hi\"}]}"
},
1 = {
texture: "textures/items/apple",
command: "give @p apple 1"
},
2 = {
texture: "textures/items/apple",
command: "give @p apple 1"
},
3 = {
texture: "textures/items/apple",
command: "give @p apple 1"
},
]
for(let i = 0; i < numberData.length; i++) form.button(i.toString(), numberData[i].texture);
form.show((r)=>{
source.runCommand(numberData[r.selection].command);
});
@rapid flume ```js
const numberData = {
5: {
texture: "textures/items/apple",
command: "source.sendMessage(hi)",
},
31: {
texture: "textures/items/apple",
command: "source.runCommandAsync(give @p apple 1)",
},
52: {
texture: "textures/items/apple",
command: "source.runCommandAsync(give @p apple 1)",
},
15: {
texture: "textures/items/apple",
command: "source.runCommandAsync(give @p apple 1)",
},
};
export function testForm(source) {
const form = new ActionFormData();
form.title(§2\n§8Chest);
form.body(``);
const commands = Object.keys(numberData).map((key) => {
form.button(key, numberData[key].texture)
return numberData[key].command
});
form.show(source).then((result) => {
if (result.canceled) return;
const buttonNumber = result.selection;
eval(commands[buttonNumber]);
});
};```
could you fix this? js export function testForm(source) { const form = new ActionFormData(); form.title(`§2\n§8Chest ${getItemCount(source, "minecraft:apple")}`); form.body(``); const numberData = {}; const randomCount = Math.round(Math.random() * 5) + 6; for (let i = 0; i < randomCount; i++) { let randomNumber; do { randomNumber = Math.floor(Math.random() * 64); } while (randomNumber === 58); numberData[randomNumber] = { texture: "textures/items/apple", command: "source.sendMessage('hi')", }; } numberData[58] = { texture: "textures/items/diamond", command: "source.sendMessage(`test`)", }; const numbers = Array.from({ length: 63 }, (_, index) => index); numbers.forEach((buttonNumber) => { const buttonData = numberData[buttonNumber]; const buttonTexture = buttonData ? buttonData.texture : undefined; form.button(`${buttonNumber}`, buttonTexture); }); form.show(source).then((result) => { const buttonNumber = result.selection; const buttonData = numberData[buttonNumber]; if (buttonData && buttonData.command && buttonNumber !== 58) { buttonData.command; source.sendMessage(`You lost!!`); source.playSound("cauldron.explode"); } else if (!result.canceled && buttonNumber !== 58) { source.sendMessage(`You won!!`); source.playSound("random.levelup"); } else if (buttonNumber === 58) { numberData[58].command; } }); } i reserved slot 58 but its not running the slot 58 command
@rapid flume did u even try this?
no, this is something different
explain how many buttons should be there
oh nvm, it's like putting the original button in random button
is the dia texture supposed to be there?
eval()