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

[Lua][Question] How to suck a specified number of items out of a chest?

Started by Bancey, 24 February 2013 - 02:49 AM
Bancey #1
Posted 24 February 2013 - 03:49 AM
Title: "[Lua][Question] How to suck a specified number of items out of a chest?

Title sums it up really, but I was wondering if there was a way to pull a certain number of items out if a chest. For example I was trying to use turtle.suck(4), however this pulls out as many as it can from the first slot,
Is this supposed to happen or is it a bug?
Also any differant idea's on how to do this?
Thanks
-Bancey
SuicidalSTDz #2
Posted 24 February 2013 - 10:44 AM
This is not a bug, however, I believe the mod MiscPeripherals by RichardG allows more in depth "inventory management" methods
Bancey #3
Posted 25 February 2013 - 04:50 AM
Ah, got it. I'll have a look into it but this seams to be able to do waht I want.
Thanks :D/>
theoriginalbit #4
Posted 25 February 2013 - 04:59 AM
Also you could do this.


turtle.suck() -- gets all items
local wanted = 24
local actuallyGot = turtle.getItemCount( 1 ) -- where one is the slot we just sucked into
if actuallyGot - wanted == 0 then
  print("We got the perfect amount")
elseif actuallyGot - wanted > 0 then
  turtle.drop( actuallyGot - wanted ) -- drop off the excess
else
  print("We didn't get as many as we wanted :(/>")
end
SuicidalSTDz #5
Posted 25 February 2013 - 07:19 AM
Also you could do this.


turtle.suck() -- gets all items
local wanted = 24
local actuallyGot = turtle.getItemCount( 1 ) -- where one is the slot we just sucked into
if actuallyGot - wanted == 0 then
  print("We got the perfect amount")
elseif actuallyGot - wanted > 0 then
  turtle.drop( actuallyGot - wanted ) -- drop off the excess
else
  print("We didn't get as many as we wanted :(/>/>/>")
end
Pretty good solution actually :)/>/> not that I expected anything less from BIT :D/>