#Help

1 messages · Page 1 of 1 (latest)

old mantleBOT
#
Debug Result

There are 3 errors in this [code](#1132431990029824171 message):

newui.js:24:22 - error TS18048: 'r.formValues' is possibly 'undefined'.

24         let slider = r.formValues[0];
                        ~~~~~~~~~~~~

``````ansi
newui.js:25:22 - error TS18048: 'r.formValues' is possibly 'undefined'.

25         let toggle = r.formValues[1];
                        ~~~~~~~~~~~~

``````ansi
newui.js:35:9 - error TS1107: Jump target cannot cross function boundary.

35         break;
           ~~~~~~

dull karma
#

just remove the break statement

#
import {
    world
} from "@minecraft/server"
import {
    ActionFormData,
    ModalFormData,
    MessageFormData
} from "@minecraft/server-ui"

function ui5(player) {
    let form5 = new ModalFormData()
    form5.title("Iron Ingot");
    form5.slider("Amount (15 per iron_ingot)",
        0,
        64,
        1)
    form5.toggle("Confirm",
        false)
    form5.show(player).then(r => {
        // This will stop the code when the player closes the form
        if (r.canceled) return;

        // This will assign every input their own variable
        let slider = r.formValues[0];
        let toggle = r.formValues[1];

        // Do something
        player.runCommandAsync('scoreboard players set @s goldprice 15');
        player.runCommandAsync('scoreboard players set @s slider ${slider}');
        player.runCommandAsync('scoreboard players operation @s goldprice *= @s slider');
        player.runCommandAsync('execute if score @s goldprice <= @s gold run scoreboard players operation @s gold -= @s goldprice');
        player.runCommandAsync('execute if score @s goldprice <= @s gold run give @s iron_ingot ${slider}');
        player.runCommandAsync('execute if score @s goldprice <= @s gold run tellraw @a {"rawtext":[{"text":"§r§7You succesfully bought iron_ingot x${slider}"}]}');
        player.runCommandAsync('execute if score @s goldprice > @s gold run tellraw @s {"rawtext":[{"text":"§r§7You do not have enough money to buy iron_ingot x${slider}"}]}');
    }).catch(e => {
        console.error(e, e.stack);
    });
}



world.afterEvents.itemUse.subscribe((data) => {
    const {
        source: player,
        itemStack
    } = data

    if (itemStack.typeId == "minecraft:gold_ingot") {
        ui5(player)
    }
})
#

the other 2 errors are not a problem, I think. It can still work even with those two errors.

indigo shuttle
indigo shuttle
dull karma
#

use `

#

instead of '

indigo shuttle
#

I'll try it, thank you

dull karma
#
`String ${variable}`