#itemUse

1 messages · Page 1 of 1 (latest)

snow lantern
#

world.events.itemUse.subscribe(ev => {
    if (ev.item.id == 'minecraft:clock' && ev.source.id == 'minecraft:player') {
        var source = ev.source;
        form.show(ev.source).then(res => {
            source.runCommand(`tellraw @a {"rawtext":[{"text":"test complete ${res.selection + 1}"}]}`);
        });
    }
});```
Anyone able tell me why this doesn't work / what needs to be changed. 

Much appreciated
charred grove
# snow lantern ```js world.events.itemUse.subscribe(ev => { if (ev.item.id == 'minecraft:c...
import { world, Player } from 'minecraft/server';

world.beforeEvents.itemUse.subscribe(ev => {
    if (ev.itemStack.id == 'minecraft:clock' && !ev.source instanceof Player) {
        var source = ev.source;
        form.show(ev.source).then(res => {
            source.runCommand(`tellraw @a {"rawtext":[{"text":"test complete ${res.selection + 1}"}]}`);
        });
    }
});```

Please use #1067535382285135923 later on.
snow lantern
snow lantern
#

Not getting anymore errors, it's just not openinh

arctic cove
arctic cove
muted zephyr
arctic cove
#

@muted zephyr is right,

If form is not defined, nothing will show, though there should be an error message ...

Try:

import { world, Player } from 'minecraft/server';

world.beforeEvents.itemUse.subscribe(ev => {
    if (ev.itemStack.id == 'minecraft:clock') {
        var source = ev.source;
        let form = new ActionFormData();
form.title("title");
form.button("button1");
form.show(source).then(res => {
            source.runCommand(`tellraw @a {"rawtext":[{"text":`test complete ${res.selection + 1}`}]}`);
        });
    }
});```
And enable the logs