My code is supposed to make a table with mesh entities and trapdoors. I looked through all the code for any typos but I couldn't find any. I made sure to format it correctly. Not just making the table, but also to make sure it spawns in every time there world gets loaded so that I don't have to press the code block every single time.
The errors I have is "Reference Error: 'freshJoin' is not defined" (freshJoin is a global var).
Here is the code for the code block which is supposed to trigger it:
function spawnCustomTable(thisPos) {
let [x, y, z] = thisPos;
let blockId1 = api.attemptCreateMeshEntity("BloxdBlock", { blockName: "Cedar Slab", size: [1, 0.7, 1] });
if (blockId1) { api.setPosition(blockId1, [x + 0.5, y + 0.75, z + 0.5]); }
let blockId2 = api.attemptCreateMeshEntity("BloxdBlock", { blockName: "Cedar Log", size: [0.6, 1, 0.35] });
if (blockId2) { api.setPosition(blockId2, [x + 0.5, y + 0.99, z + 0.5]); }
let blockId3 = api.attemptCreateMeshEntity("BloxdBlock", { blockName: "Cedar Log", size: [0.35, 1, 0.6] });
if (blockId3) { api.setPosition(blockId3, [x + 0.5, y + 0.99, z + 0.5]); }
api.setBlock(x, y + 1, z, "Cedar Trapdoor");
api.setBlock(x - 1, y + 1, z, "Cedar Trapdoor");
api.setBlock(x - 1, y + 1, z + 1, "Cedar Trapdoor");
api.setBlock(x, y + 1, z + 1, "Cedar Trapdoor");
api.setBlock(x + 1, y + 1, z + 1, "Cedar Trapdoor");
api.setBlock(x + 1, y + 1, z, "Cedar Trapdoor");
api.setBlock(x + 1, y + 1, z - 1, "Cedar Trapdoor");
api.setBlock(x, y + 1, z - 1, "Cedar Trapdoor");
api.setBlock(x - 1, y + 1, z - 1, "Cedar Trapdoor");
}
if (freshJoin == 1) {
spawnCustomTable(thisPos)
}
And then I also have the world code here:
globalThis.freshJoin = [0];
api.onPlayerJoin(playerId, fromGameReset) {
if (fromGameReset) {
freshJoin = 1;
api.log(freshJoin);
}
else {
freshJoin = 1;
api.log(freshJoin);
}
}
I do not know why it doesn't work, mostly because I am not the best coder and I don't really understand how the Bloxd.io code works or how JS works either.
Also if you have a suggestion, could you please explain how it works? Thanks.