This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gheotic's profile picture

Resupply a turtle

Started by gheotic, 03 February 2013 - 08:51 AM
gheotic #1
Posted 03 February 2013 - 09:51 AM
Hey everybody who is reading this :)/>

im trying to make a lumberjack program that place saplings and use bone meal on it then cut it down again
but to make it fully automatic i need to make it resupply it self i have 3 stuff so 1 slot for fuel 1 slot for bone meal and 1 slot for sappling

how can i make it resupply it self from a chest???
Viproz #2
Posted 03 February 2013 - 10:04 AM
You can do turtle.suck() when there is a chest in front (or turtle.suckUp/down())
gheotic #3
Posted 03 February 2013 - 10:09 AM
but it hard to organise it that way :/
shiphorns #4
Posted 03 February 2013 - 02:23 PM
but it hard to organise it that way :/
When you go to place saplings, or use bonemeal, or consume a fuel, just make it so your program considers each slot to be empty when it gets down to a count of 1 instead of 0. When, when you suck() from your refill chests, it will automatically refill matching items into those stacks. Or you can have separate refill chests for each item type, and dumping (using drop()) and select each designated slot before sucking items from the corresponding chest. I personally like the former approach, where you keep a reference item.

Either way, it will be simplest if you refill each item from a separate chest that contains only that item. I suggest this because you don't get to pick which chest slot suck() takes from, you just get whatever is in the chest's first empty slot, so in order to refill 2 or more item types from one chest and make sure you refill with some of each of the required items–making no assumptions about how the chest is organized or sorted–you would have to suck from one chest into an empty turtle slot(s), use compareTo() and transferTo() against reference items to get things onto the right stacks, and then drop() unmatching items or items you've already got enough of into another chest so that you don't get in a loop where you keep sucking up and returning one item type over and over and never get all the things you need.
Kingdaro #5
Posted 03 February 2013 - 02:44 PM
When, when you suck() from your refill chests, it will automatically refill matching items into those stacks.

Sadly, this isn't the case. I just did a test, where the turtle had a sapling for reference in its selected slot, and saplings were in the chest, but coal was the first thing immediately suck-able, the coal was sucked anyway, and the selected saplings did not get filled.
shiphorns #6
Posted 04 February 2013 - 05:33 AM
When, when you suck() from your refill chests, it will automatically refill matching items into those stacks.

Sadly, this isn't the case. I just did a test, where the turtle had a sapling for reference in its selected slot, and saplings were in the chest, but coal was the first thing immediately suck-able, the coal was sucked anyway, and the selected saplings did not get filled.

Sorry, you misunderstood me. I didn't mean that the turtle could be told to suck() a specific type preferentially. suck() will always take the first thing from a chest (starting in the upper right, going left to right, then top to bottom). You can't control that. But when it does get to the saplings in the chest, it will stack them on top of the reference sapling already in the turtle inventory. So.. you can keep doing suck() until you detect that the count on that stack has gone up. Things that are not the reference items will end up in the turtle's free slots. Each time the turtle fills, you should drop() those unwanted sucked-up items elsewhere, like into another chest to the right, or something like that. But… if it's filled one more of the reference stacks and still sucking types of items it can use (for example, if it's filled the sapling stack, still looking for bonemeal, but also still sucking up more saplings) then you need to use compareTo() on the free slots so that you only purge items you don't need, you can't just blindly drop() the contents of the non-reference slots.

This is why I recommended having a chest that contains only saplings (and another with bonemeal, another for fuel). It's more work to write all the code to rummage through a chest of potentially many types of items and filter out what you need.