#Creating an array of blocks in KubeJS

5 messages · Page 1 of 1 (latest)

narrow ridge
#

I'm trying to destroy a group of blocks, and it works if I just enter them line by line manually to destroy them, but I'd like to understand why it doesn't work in an array.

My attempt at code:
`BlockEvents.broken(event => {
let brBlock = event.getBlock();
let brBlockD = brBlock.down;

const desBlocks = [BlockPos(brBlockD.x + 1, brBlockD.y, brBlockD.z),
    BlockPos(brBlockD.x - 1, brBlockD.y, brBlockD.z),
    BlockPos(brBlockD.x, brBlockD.y - 1, brBlockD.z),
    BlockPos(brBlockD.x, brBlockD.y, brBlockD.z + 1),
    BlockPos(brBlockD.x, brBlockD.y, brBlockD.z - 1)];

    event.player.tell(`${desBlocks}`);

desBlocks.forEach((block, index) => {
    event.level.destroyBlock(block, true);
});

}

});`

On the line with my array declaration, the KubeJS server log gives the error "TypeError: redeclaration of var desBlocks", but I've tried it with event.level.getBlock(brBlockD.x, brBlockD.y, brBlockD.z) for the array entries, and get the same issue.

Is it assuming desBlocks is something other than an array? I'm very lost. :/

coarse marshBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

tall mistBOT
#

You can write your code in a codeblock by typing it between the codeblock delimiters:
Note that these are backticks, not apostrophes

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

This example will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
fallen fjord
#

Replace const with let

narrow ridge
#

🥲 It worked perfectly. Thank you!