#how to make form function say hello

1 messages · Page 1 of 1 (latest)

uncut plover
#

how to make form function say hello

lyric skiff
uncut plover
#

I've tried it but it doesn't work

crystal birch
#

try removing player in parentheses function

uncut plover
#

So how can the form be shown to the player?

#

Function hello () {} ?

crystal birch
#

can you send your code so I can edit it?

uncut plover
#

function hello(player) {
const f = new ActionFormData()
f.title('hello')
f.body('hello')
f.button('hello')
f.show(player).then((r) => {
const selection = r.selection
})
}

world.afterEvents.itemUse.subscribe((r) => {
const player = r.source
const item = r.itemStack.typeId

if (item === "minecraft:compass") {
    hello(player)
}

})

crystal birch
#

Thank you

#

you tried to see if without putting it in a function it worked

uncut plover
#

Yeah ik but it will nested and hard to read

crystal birch
#

yes I agree but does it work without the function

#

if so I could look into putting it in a function afterwards

uncut plover
#

Welp the function only can show the form

crystal birch
#

No

#

I'm on my phone I don't have my scripts to give you an example that would work 100% but I assure you that it works

uncut plover
crystal birch
#

but just your consistency until the end of your function instead of the name of your function

uncut plover
#

Hmm do you think asynchronous may work ?

crystal birch
#

I already did it in the past it worked after now I use functions

uncut plover
#

So how you do it

uncut plover
#

Uhh okay can you send the example code

crystal birch
#

when I have my PC

pearl shaleBOT
quiet vessel
#
import { world } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

function hello(player) {
    const form = new ActionFormData()
    form.title('hello')
    form.body('hello')
    form.button('hello')
    form.show(player).then(result => {

        if (result.selection === 0) {
            player.runCommandAsync('execute as @a at @s run summon snowball ~ ~ ~')
            player.sendMessage(`§aHello!`)
    }}
)}


world.afterEvents.itemUse.subscribe((r) => {
    const player = r.source
    const item = r.itemStack.typeId

    if (item === "minecraft:compass") {
        hello(player)
    }
})
#

@uncut plover