OpenMods / OpenPeripheral

https://openmods.info
MIT License
67 stars 25 forks source link

Issue with getAvailableItems() for AE2 and Computercraft openp api #268

Closed xxakirhaxx closed 8 years ago

xxakirhaxx commented 8 years ago

I'm unsure if this is the place to post this, since it might be an issue with AE2 or computercraft. I'm running a script in computercraft to look through my AE system. I'm using openPeripheral functions connected to an ME interface to run the command interface.getAvailableItems(). This returns an array of item data, most notably the item fingerprint. I then pull item details from the fingerprint using interface.getItemDetail(interface.getAvailableItems()[i].fingerprint). I'm not sure why but sometimes when going through the for loop of interface.getAvailableItems() the iterator will go out of scope of the array returned. This likely happens because I'm using LUA and LUA runs the second argument for the for loop once and stores the data, rather than running it each time to get a new value. What's worse is that once I've obtained an i value to look up an item in the array, sometimes the i is in scope, and sometimes it's not (according to the errors I'm getting) and it's not consistent either. Sometimes it will do it on Iron Blocks, sometimes on Cryo-Stabilized Flux Ducts, and sometimes on Cobblestone. I found a way around this, to check weather the look up value went out of scope. I threw an exception, and tried again, but not only does this make looking up items take waaaaaaay too long, sometimes after it gets the fingerprint for the item, the fingerprint will fail to look up the item details in the interface.getItemDetail(fingerprint) function. And this also isn't consistent, sometimes it will fail to look up the display_name, other times it will fail to look up the dmg or the qty. I'm unsure if this is a bug or just part of the way that lua + java running in minecraft have to work together. Either way it seems like a bug. If you need more information I can post it here. Then again I'm unsure if this belongs here, if it doesn't please close the issue. Thank you for time if you read all of this. :)

I posted basically the same thing over at the AE2 github board because I'm unsure if this is an issue and if it is, what board it belongs to. If it doesn't belong here, please close it. Thank you.

boq commented 8 years ago

You are assuming that getAvailableItems will always return same elements - but it is not true when contents of AE network change. And it's actually extremely slow, since every lookup requires iteration over ALL available items.

I suggest using getAvailableItems("PROXY") or getAvailableItems("ALL") and keeping result in local variable - this will allow to skip extra calls to getItemDetail and possible race conditions.

xxakirhaxx commented 8 years ago

Thank you, this is what I was thinking was happening. Is there somewhere I could find out what the arguments "proxy" and "all" do? I'm going to check a few avenues where I think they might be, but I feel like I've looked in the past and didn't find them, at least with the proxy argument.

xxakirhaxx commented 8 years ago

Just wanted to report back. I found out what proxy does. I rewrote the code to take advantage of snapshoting the available items and then iterating through and picking up item details with it. And now my itemGet network is working flawlessly. I can now run up to 20 turtles with an ender chest to build anything as long as the items exist in my AE system. Thank you so much. I'm awaiting to see what will happen when I call request crafting. I let the snap shot qty be the check as to weather to craft something, but I'm worried about crafting something, and a separate turtle snapshoting the amount it needs and taking from what the other turtle is crafting. For that reason I left in the getItemDetails() for checking current qty (because that's what it does...I hope). Other than that. It works great. Thank you again.

boq commented 8 years ago

Closing. Please remember to close https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/2283 too.

J0B10 commented 5 years ago

I know answering to 3 years old, closed issue is what most people would call spam, but let me ecplain my problem:

I've gone back to play the good old mods we used to play when we were at school.

In detail I want to make a computer that checks how much of certain item types are in an ae2 me system and if they are lower than a given number requests to craft them.

I was confused what the proxy in getAvailableItems() and getItemDetail() does and I couldn't find any information on this using google except for this issue.

So @xxakirhaxx you said you found out what it does, do you still know and could you help me?

I hope somebody even reads this xD

xxakirhaxx commented 5 years ago

I found the code I used to make this, but I didn't comment anything. I can't remember what proxy does,I hope this helps. I'm sharing a file containing the function that I was referencing in the post. The function's name is getItem(id, itemName, amount,...) it would search through AE and find an item by 'itemName' and check if the 'amount' then either get it and export it or craft it and export it. The 'id' was internal I believe, for identifying whatever was interacting with the function.

I'm sorry I can't be more helpful. If I just go off of spotty memory, I think proxy allowed you to take a prepared snapshot of your AE inventory. Without proxy, I think it tried to pull up bad information and if you tried to interact with the network without using proxy some data wouldn't match up.

Best of luck on whatever your project is. :)

On Sun, Aug 4, 2019 at 9:35 PM Jonas notifications@github.com wrote:

I know answering to 3 years old, closed issue is what most people would call spam, but let me ecplain my problem:

I've gone back to play the good old mods we used to play when we were at school.

In detail I want to make a computer that checks how much of certain item types are in an ae2 me system and if they are lower than a given number requests to craft them.

I was confused what the proxy in getAvailableItems() and getItemDetail() does and I couldn't find any information on this using google except for this issue.

So @xxakirhaxx https://github.com/xxakirhaxx you said you found out what it does, do you still know and could you help me?

I hope somebody even reads this xD

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/OpenMods/OpenPeripheral/issues/268?email_source=notifications&email_token=AAOSXGIEERMEEYAVIYTWIFTQC6UYNA5CNFSM4CEG3XUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3QU57Q#issuecomment-518082302, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOSXGNRI6KB23QSP2S7OZLQC6UYNANCNFSM4CEG3XUA .

xxakirhaxx commented 5 years ago

Aaaaand forgot to attach the code.

On Mon, Aug 5, 2019 at 4:44 PM Jeff Bond xxakirhaxx@gmail.com wrote:

I found the code I used to make this, but I didn't comment anything. I can't remember what proxy does,I hope this helps. I'm sharing a file containing the function that I was referencing in the post. The function's name is getItem(id, itemName, amount,...) it would search through AE and find an item by 'itemName' and check if the 'amount' then either get it and export it or craft it and export it. The 'id' was internal I believe, for identifying whatever was interacting with the function.

I'm sorry I can't be more helpful. If I just go off of spotty memory, I think proxy allowed you to take a prepared snapshot of your AE inventory. Without proxy, I think it tried to pull up bad information and if you tried to interact with the network without using proxy some data wouldn't match up.

Best of luck on whatever your project is. :)

On Sun, Aug 4, 2019 at 9:35 PM Jonas notifications@github.com wrote:

I know answering to 3 years old, closed issue is what most people would call spam, but let me ecplain my problem:

I've gone back to play the good old mods we used to play when we were at school.

In detail I want to make a computer that checks how much of certain item types are in an ae2 me system and if they are lower than a given number requests to craft them.

I was confused what the proxy in getAvailableItems() and getItemDetail() does and I couldn't find any information on this using google except for this issue.

So @xxakirhaxx https://github.com/xxakirhaxx you said you found out what it does, do you still know and could you help me?

I hope somebody even reads this xD

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/OpenMods/OpenPeripheral/issues/268?email_source=notifications&email_token=AAOSXGIEERMEEYAVIYTWIFTQC6UYNA5CNFSM4CEG3XUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3QU57Q#issuecomment-518082302, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOSXGNRI6KB23QSP2S7OZLQC6UYNANCNFSM4CEG3XUA .