Error: (How do i fix ?)
"[Scripting][error]-TypeError: cannot read property 'nameTag' of undefined at <InwAitJi> (test.js:223)"
/** _______________________________________________________ */
const typeIdNotDiamond = [
"minecraft:stone_sword",
"minecraft:golden_sword",
"minecraft:iron_sword",
"minecraft:bow",
]
const gotIdNotDiamond = [
"pa:sword_piece",
"pa:sword_piece",
"pa:sword_piece",
"pa:string_piece",
]
const gotCountNotDiamond = [
1,
2,
3,
3,
]
/** _______________________________________________________ */
// getAll ! diamond, nameTag
function getAll(pl) {
system.run(() => {
const inv = pl.getComponent("inventory").container;
let foundCount = [];
let sell = [];
let total = 0;
for (let i = 0; i < typeIdNotDiamond.length; i++) {
for (let p = 0; p < inv.size; p++) {
if (typeof inv.getItem(p).nameTag === undefined) continue
if (typeof inv.getItem(p) === "undefined" || typeof inv.getItem(p) === undefined) continue
if (inv.getItem(p).typeId === typeIdNotDiamond[i]) {
total += inv.getItem(p).amount;
sell.push(typeIdNotDiamond[i]);
foundCount.push(gotCountNotDiamond[i] * total);
}
}
}
let display = [];
for (let i = 0; i < foundCount.length; i++) {
display.push(`${sell[i]} x${foundCount[i]}`);
}
pl.sendMessage(`All Found: ${display.join("\n")}`);
})
}