#Type Error: not a function

1 messages · Page 1 of 1 (latest)

junior cargo
#

The button in the menu leads to a second shop_menu. inside the shop menu is a "go back to menu" button but it doesnt work.

export function menu(player) {
    const menu = new ActionFormData()
    menu.title('§m§a§g§lMenu')
    menu.button('§2Shop\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t§qBuy Items', 'textures/items/minecart_chest')
    menu.show(player).then(r => {
        if (r.selection == 0) { menu_shop(player); }
    })
}

function menu_shop(player) {
    let coins = world.scoreboard.getObjective('coins').getScore(player)
    const menu = new ActionFormData()
    menu.title('§m§f§g§lMenu§r§p × Shop')
    menu.button('§4§lGo Back\n§r§8To Menu', 'textures/ui/cancel')
    menu.button('§7Workbench\n§g4\uE106', 'textures/blocks/crafting_table_side')
    menu.button('§94x §7Dirt\n§g32\uE106', 'textures/blocks/dirt')
    menu.button('§98x §7Glass\n§g48\uE106', 'textures/blocks/glass')
    menu.button('§7Awkward Pot\n§g32\uE106', 'textures/items/potion_bottle_absorption')
    menu.button('Jungle Tree\n§g640\uE106', 'textures/blocks/sapling_jungle')
    menu.show(player).then(r => {
    if (r.selection === 1) {buy_item(player,4,"Workbench","crafting_table", 1, 0);}
    else if (r.selection === 2) {buy_item(player,32,"Dirt","dirt", 4, 0);}
    else if (r.selection === 0) {menu(player);}
})}
wide sorrel
#

@junior cargo Give me the error.

junior cargo
#

how can i get it?

junior cargo
#

@wide sorrel

round thistle
#

Use .catch after .then to record a more accurate log of the unhandled promise rejection.

junior cargo
#

can you tel me where ? ':)

#

where do i need to put the .catch

round thistle
#

Menu

export function menu(player) {
    const menu = new ActionFormData()
    menu.title('§m§a§g§lMenu')
    menu.button('§2Shop\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t§qBuy Items', 'textures/items/minecart_chest')
    menu.show(player)
        .then(r => {
            if (r.selection == 0) { menu_shop(player); }
        })
        .catch(error => {
            console.error("Unhandled Rejection: ", error);
            if (error instanceof Error) {
                const stackLines = error.stack.split("\n");
                if (stackLines.length > 1) {
                    const sourceInfo = stackLines;
                    console.error("Error originated from:", sourceInfo[0]);
                }
            }
        });
}
#

Menu Shop

function menu_shop(player) {
    let coins = world.scoreboard.getObjective('coins').getScore(player)
    const menu = new ActionFormData()
    menu.title('§m§f§g§lMenu§r§p × Shop')
    menu.button('§4§lGo Back\n§r§8To Menu', 'textures/ui/cancel')
    menu.button('§7Workbench\n§g4\uE106', 'textures/blocks/crafting_table_side')
    menu.button('§94x §7Dirt\n§g32\uE106', 'textures/blocks/dirt')
    menu.button('§98x §7Glass\n§g48\uE106', 'textures/blocks/glass')
    menu.button('§7Awkward Pot\n§g32\uE106', 'textures/items/potion_bottle_absorption')
    menu.button('Jungle Tree\n§g640\uE106', 'textures/blocks/sapling_jungle')
    menu.show(player)
        .then(r => {
            if (r.selection === 1) { buy_item(player, 4, "Workbench", "crafting_table", 1, 0); }
            else if (r.selection === 2) { buy_item(player, 32, "Dirt", "dirt", 4, 0); }
            else if (r.selection === 0) { menu(player); }
        })
        .catch(error => {
            console.error("Unhandled Rejection: ", error);
            if (error instanceof Error) {
                const stackLines = error.stack.split("\n");
                if (stackLines.length > 1) {
                    const sourceInfo = stackLines;
                    console.error("Error originated from:", sourceInfo[0]);
                }
            }
        });
}
junior cargo
#

okay i will try it

round thistle
#

What is line 86

wide sorrel
junior cargo
#
            else if (r.selection === 0) { menu(player); }```
#

so it doesnt know who the player is?

junior cargo
wide sorrel
#

hm

junior cargo
#

thats weird becuase the other functions do work

#

like the buy_item function

wide sorrel
#

How do you call functions?

junior cargo
#

?

round thistle
#

Hold on to that code I shared with you for logging errors. It's useful when dealing with unhandled promise rejections.

junior cargo
#

yes

junior cargo
round thistle
junior cargo
#
function menu_shop(player) {
    let coins = world.scoreboard.getObjective('coins').getScore(player)
    const menu = new ActionFormData()
    menu.title('§m§f§g§lMenu§r§p × Shop')
    menu.button('§4§lGo Back\n§r§8To Menu', 'textures/ui/cancel')
    menu.button('§7Workbench\n§g4\uE106', 'textures/blocks/crafting_table_side')
    menu.button('§94x §7Dirt\n§g32\uE106', 'textures/blocks/dirt')
    menu.button('§98x §7Glass\n§g48\uE106', 'textures/blocks/glass')
    menu.button('§7Awkward Pot\n§g32\uE106', 'textures/items/potion_bottle_absorption')
    menu.button('Jungle Tree\n§g640\uE106', 'textures/blocks/sapling_jungle')
    menu.show(player)
        .then(r => {
            if (r.selection === 1) { buy_item(player, 4, "Workbench", "crafting_table", 1, 0); }
            else if (r.selection === 2) { buy_item(player, 32, "Dirt", "dirt", 4, 0); }
            else if (r.selection === 0) { 
                player.sendMessage("You exist")
                menu(player, 0); 
            }
        })
        .catch(error => {
            console.error("Unhandled Rejection: ", error);
            if (error instanceof Error) {
                const stackLines = error.stack.split("\n");
                if (stackLines.length > 1) {
                    const sourceInfo = stackLines;
                    console.error("Error originated from:", sourceInfo[0]);
                }
            }
        });
}``` the player object exists
summer mantle
#

it ovverides menu function

#

and you trying to call const menu = new ActionFormData()

#

thats why its not a function

junior cargo
#

oh

#

how can i resolve this?

summer mantle
#

rename either local variable or function menu

junior cargo
#

makes alota sense

#

thanks alot