#ui not working

1 messages · Page 1 of 1 (latest)

brave nebula
#
world.beforeEvents.chatSend.subscribe(async (data) => {
    const { message, sender: player } = data;
    if (message === "-bp") {
         let title = "bbb";
         system.run(() => {
            first(player, title);
         });
    }
});

export async function first(player, title, source) {
    const form = new ChestFormData("45");
    form.title(title);
    form.pattern([
        "_________",
        "_________",
        "_________",
        "_________",
        "xxyyyyyxx",
    ], {
        x: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_red" },
        y: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_orange" },
    });
    const response = await forceShow(player, form);
    await system.waitTicks(2);
     uiManager.closeAllForms(player);
     second(player, title)(
}

Why i should cancel form to play the second ui? how to solve this so it will play second form when i closed chat?

brave nebula
#

anyone

brave frigate
#

rephrase please

brave nebula
# brave frigate rephrase please

Why do I need to cancel the first form in order to display the second form? How can I ensure that the second form is displayed after “system.waitTicks(2)”, without needing to cancel the first form?

brave nebula
#

I should cancel form to make it work

steady flower
#

wdym

brave nebula
#

try it out yourself

brave nebula
#

???

#

ANYONE

sweet breach
#

You don't need to cancel the first form for the second form to show up. I can't see the code to your other functions leading to the second form but when you create a new instance of the form it should just pop open that form and the other closes automatically. I'm not familiar with this custom form you have: ChestFormData.

brave nebula
sweet breach
glossy finch
sweet breach
#

Indeed, otherwise I can only speculate.

brave nebula
# sweet breach Indeed, otherwise I can only speculate.
import { world, system } from "@minecraft/server";
import { uiManager } from "@minecraft/server-ui";
import { forceShow } from "./utils.js"; 
world.beforeEvents.chatSend.subscribe(async (data) => {
    const { message, sender: player } = data;
    if (message === "-bp") {
         let title = "bbb";
         system.run(() => {
            first(player, title);
         });
    }
});

async function first(player, title) {
    const form = new ChestFormData("45");
    form.title(title);
    form.pattern([
        "_________",
        "_________",
        "_________",
        "_________",
        "xxyyyyyxx",
    ], {
        x: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_red" },
        y: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_orange" },
    });
    const response = await forceShow(player, form);
    await system.waitTicks(2);
     uiManager.closeAllForms(player);
     second(player, title)
}

async function second(player, title) {
    const form = new ChestFormData("45");
    form.title(title);
    form.pattern([
        "_________",
        "_________",
        "_________",
        "xyyyyyyyx",
        "xxyyyyyxx",
    ], {
        x: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_red" },
        y: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_orange" },
    });
    await form.show(player);
}
brave nebula
#

now can you?

brave nebula
#

???

sweet breach
brave nebula
#

alr

brave nebula
sweet breach
#

Thanks, bare with me. I am busy with my family - still celebrating the holidays.

brave nebula
#

k

sweet breach
# brave nebula k
world.beforeEvents.chatSend.subscribe(async (data) => {
    const { message, sender: player } = data;
    if (message === "-bp") {
        const title = "bbb";
        first(player, title);
    }
});

function first(player, title) {
    const form1 = new ChestFormData("45");
    form1.title(title);
    form1.button(1, '§l§3Test Item 1', ['', '§r§7A testing item', 'Click any item!'], 'minecraft:filled_end_portal_frame', 2)


    form1.show(player).then(response => {
        if (response?.cancelationReason === "UserBusy") {
            console.log("Player is busy, retrying...");
            system.waitTicks(20);
            return first(player, title);
        }
        if (response?.canceled) {
            return;
        }
        console.log(`${player.name} has chosen item ${response.selection}`);
        return second(player, title);
    }).catch((error) => {
        console.error("Error showing first form:", error);
    })
}

function second(player, title) {
    const form2 = new ChestFormData("45");
    form2.title(title);
    form2.button(0, '§l§4Back', ['', '§r§cGo back a page!'], 'textures/blocks/barrier')
    form2.pattern([
        "_________",
        "_________",
        "_________",
        "xyyyyyyyx",
        "xxyyyyyxx",
    ], {
        x: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_red" },
        y: { itemName: "glass", stackAmount: 1, texture: "textures/blocks/glass_orange" },
    });

    form2.show(player).then(response => {
        if (response?.canceled) {
            return;
        }
        if (response?.selection === 0) {
            return first(player, title);
        }
        console.log(`Second Form has appeared`);
    }).catch((error) => {
        console.error("Error showing first form:", error);
    })
}
#

The parameters filled in for the buttons is based on the assumption that you are using the ChestFormData Class from Herobrines Chest-UI project.

brave nebula
rare wigeon
#

@sweet breach sorry for ping, are you familiar with this chest Ui by herobrine?

brave nebula
#

anyone knows the solution?

sweet breach
#

I'm not really sure what your end goal is so maybe someone else can assist.

sweet breach
brave nebula
rare wigeon
brave nebula
#

help

brave nebula
#

is it solvable?

brave nebula
#

anyone

rare wigeon
#
        if (response?.selection === 0) {
            return first(player, title);
        }

Why you have there return first? And why you use (player, title)???
Also you useless function form build. There is no need to make const form1 or form2 -> you can just make new ChestFormData('45')

rare wigeon
#

I think your issues/errors are by using this type of return second(player, title); returning to menu. It can be done like this

#
            if (r.selection == <NUMBER>) {
                <FUNCTION_NAME>(player);
                return;
            }
sweet breach
#

The return logic doesn't matter. Either way works. It was more or less to get it functional so they could extend it how they needed it, but there is confusion on what they actually need and it partially doesn't make sense so I stepped away. Based on what I am understanding they want the first form to show up for the player but then they want the second form to automatically appear right after. In such a case, it makes no sense to me to have the first one appear since it's going to be replaced by the second one instantaneously. So I do not understand why they need both if only the second one is going to be visible by nature.

rare wigeon
#

Sure, sorry for my message, I just tried understand his logic in your code and it is strange 😛