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

Best Way To "turtle.suck()" Specific Amount of Items

Started by elfin8er, 14 January 2014 - 09:04 PM
elfin8er #1
Posted 14 January 2014 - 10:04 PM
I'm trying to get a mining turtle to suck a specific amount of items out of a chest, move to a location, and drop them all out. Here's the code that I have.


amount = 15
while turtle.getItemCount(1) == 0 do
  turtle.suck()
  turtle.drop(turtle.getItemCount(1) - amount
end

Also, is there anyway that the turtle can take from other slots in the chest, or does it only take from the first slot? I already know that everything in the chest is the same item. I just need to be able to take a specific amount of items from the chest.
Edited on 14 January 2014 - 09:06 PM
Bomb Bloke #2
Posted 14 January 2014 - 11:10 PM
OpenPeripherals allows this. You wrap the chest as a peripheral, then tell the chest itself to move the items to the turtle. This allows you to specify which slot and how many items.

Some documentation is here, but it may or may not match your installed version.
theoriginalbit #3
Posted 14 January 2014 - 11:28 PM
the way you've done it is definitely the only way to do it in the current version of ComputerCraft (soon to change) without installing peripheral mods such as OpenPeripheral like Bomb Bloke stated.

This functionality is however changing in the new version of ComputerCraft where you'll be able to use turtle.suck with a quantity argument.
elfin8er #4
Posted 15 January 2014 - 10:16 PM
OpenPeripherals allows this. You wrap the chest as a peripheral, then tell the chest itself to move the items to the turtle. This allows you to specify which slot and how many items.

Some documentation is here, but it may or may not match your installed version.
Awesome, thanks! Woah there. I just noticed you're the same person that replied a question of mine on the FTB forums.
Bomb Bloke #5
Posted 15 January 2014 - 11:29 PM
Ah. The same question, I see. I thought it was a little bit of a coincidence to see it asked twice over a couple of days.
elfin8er #6
Posted 16 January 2014 - 01:05 AM
Ah. The same question, I see. I thought it was a little bit of a coincidence to see it asked twice over a couple of days.
Yea, slightly different, but same idea. While you're here, do you know of an easy way I don't have to specify which slot? I'm having a bit of trouble with it.
theoriginalbit #7
Posted 16 January 2014 - 01:08 AM
While you're here, do you know of an easy way I don't have to specify which slot? I'm having a bit of trouble with it.
turtle.suck will suck the items into the currently selected slot; or the next available slot in the event that the currently selected is full or the stack cannot become larger. As such just change to the slot you wish to suck into…
If you mean in relation to OpenPeripheral, nope, there's no way to perform a item movement without specifying the slot to take from.
Edited on 16 January 2014 - 12:09 AM
elfin8er #8
Posted 16 January 2014 - 01:14 AM
While you're here, do you know of an easy way I don't have to specify which slot? I'm having a bit of trouble with it.
If you mean in relation to OpenPeripheral, nope, there's no way to perform a item movement without specifying the slot to take from.
Ok, I guess I'll have to write my own function to do it then.