r/ComputerCraft • • 5d ago

Reminder the Inventory Functions can be called in Parallel

The inventory functions from CC:Tweaked have a 1 tick delay, when executed, so it kinda slows down every Project i wanted to do with multiple connected Inventories. But with parallel.waitForAny(), you can just call all at once.

Also i had trouble moving items from one Inventory to the other, if some were mixed connected to the computer/turtles side, but not visible to the network.

It doesn't seem to mention those things in the wiki. I tested on 1.20.1, not sure if its the case in later versions.

72 Upvotes

3 comments sorted by

18

u/Insurgentbullier NIH patient 5d ago

Yeah it's neat how you can just circumvent all the yielding problems.

Personally, I've been injecting a coroutine wrapper into any yielding peripheral functions and then pretending they don't yield.

local function inject_nb(fn) 
    return function(...) 
        coroutine.resume(coroutine.create(fn), ...) 
    end
end
local P = peripheral.find("a_peripheral")
P.foo = inject_nb(P.foo)

P.foo(...) -- use as normal, but now it no longer yields

8

u/ecco7777 5d ago

Thank you. Glad i saw this before optimizing my Storage System : ).

6

u/Moilli6 5d ago

Let me introduce you to the holy diagram https://ccaa.party/post/list/resource/1