function saveKit(target) {
const equ = target.getComponent(`equipable`)
const inv = target.getComponent(`inventory`)
let i = 0
for (i=0;i<9;i++) {
let item = inv.container.getItem(i)
console.warn(item.typeId, item.slot)
}
}```
ive done everything right except for `item.slot` as i dont know what should go there, im trying to retrieve the slot index of the item.
`item.slot` came back as undefined.
#need help with getItem()
1 messages · Page 1 of 1 (latest)
You mean the position where the itemStack is? u just need put "i" at that
the number of the slot it found the item in
U mean if diamond found in slot 0, dirt found in slot 1 it will return diamond 0 and dirt 1?
YES
that would be perfect if it orked
console.warn(item.typeId, i)
imso dumb
im actually so pissed i missed that
tysm bro
Don't worry, sometimes Idk what i'm doing to 🙂
sorry for bothering you again but do you know why this isnt working?
function saveKit(target) {
const equ = target.getComponent(`equipable`);
const inv = target.getComponent(`inventory`);
let i = 0;
for (i=0;i<9;i++) {
let item = inv.container.getItem(i);
if (!item === undefined) {
console.warn(item.typeId, i);
} else console.warn("empty", i)
};
};```
it makes everything go through the else dtatment
!(item ...) or item !== ... or !item
thanks
it kind of works
i got to an empty slot and it said this:
[Scripting][warning]-minecraft:totem_of_undying 0
[Scripting][warning]-minecraft:golden_apple 1
[Scripting][warning]-minecraft:glowstone 2
[Scripting][warning]-minecraft:ender_pearl 3
[Scripting][warning]-minecraft:obsidian 4
[Scripting][error]-TypeError: cannot read property 'typeId' of undefined at saveKit (index.js:433)
at <anonymous> (index.js:114)
new code:
function saveKit(target) {
const equ = target.getComponent(`equipable`);
const inv = target.getComponent(`inventory`);
let i = 0;
for (i=0;i<9;i++) {
let item = inv.container.getItem(i);
if (item.typeId !== undefined) {
console.warn(item.typeId, i);
} else console.warn("empty", i)
};
};```
The option 3 of my answer !item is wrong, correct is item
if ( item) {
console.warn(item.typeId, i)
} else { ...}
ill try that