ME Bridge getItem() throw java exception when item is referenced but not present
estafeit opened this issue ยท 12 comments
Describe
Sorry, I found another one...
Using getItem() with only item name as parameter works well but under one condition : when i take the last stack of an item from the ME (so there's no more of it) and then try to getItem() by name, I get a java exception thrown at me that stops execution. Expected is an empty return i think ?
- Doing the same with the same item, keeping one in ME works.
- Doing the same with other items (still presents in ME) works.
- Doing the same with another item, removing it from ME, does the same.
- Doing the same with a random string (ie. an unknown item) works.
It seems only referenced, but absent items are affected.
I get the name from another inventory so i'm sure it's valid.
currentseed = reprocessor.getItemDetail(1)
if (currentseed) then
print(currentseed.name)
availibleseed = bridge.getItem({name=currentseed.name})
Steps to reproduce
- Put any number of items in ME
- Remove them
- Try to call getItem() on an ME bridge with given item name as filter
Multiplayer?
No
Version
1.19.2-0.7.25r (Latest 1.19.2)
Minecraft, Forge and maybe other related mods versions
Forge 43.2.6, Minecraft 1.19.2, modpack All The Mods 8
Screenshots or Videos
No response
Crashlog/log
No response
You're using the filter wrong
name
needs to be an string, so you need to wrap it in parentheses
EDIT: I assume this is a var?
another edit...
Nvm, didn't read the whole thing. I'm sorry for that
AdvancedPeripherals-0.7.27r.zip
Could you test this version?
Unzip the file before using it
Yes it's a variable, I don't get what you mean with the parenthesis but you must be right, i got it working like this
availibleseed = bridge.getItem({name=textutils.serialize(currentseed.name)})
This return a null value.
And sure, here it is.
latest.log
I don't get what you mean with the parenthesis but you must be right, i got it working like this
That's what I meant with the edit. I thought you're just inputting a string without the quotation marks(I'm a bit tired and wrote parentheses instead of quotation marks...)
Thank you for the log, I'll look into that
Much better, no exception, and retruns an empty table/object.
Shouldn't you return nil though ? That's what i get with a random/bad item name.
Much better, no exception, and retruns an empty table/object. Shouldn't you return nil though ? That's what i get with a random/bad item name.
Not sure tbh. In some places it's an empty table, in some places it's nil
I decided to use empty tables, but ig nil would be better
If anyone needs a workaround, you can use pcall which is a bit like you would catch a exception in java.
local function getItem(id)
local ok, data = pcall(storage.getItem, {name = id})
-- if the data is nil, return an table with a zero amount
if not data then
return {name = id, amount = 0}
end
end
local cobblestone = getItem("minecraft:cobblestone")
print(cobblestone.amount)