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

Dont Pickup Cobble And Dirt

Started by Kees987, 23 October 2013 - 01:17 PM
Kees987 #1
Posted 23 October 2013 - 03:17 PM
I dont want my mining turtles to pickup dirt or cobble. Is there a way to do this?

I thought about the compare function, but in that case it needs a stack of dirt and a stack of cobble in an inventory slot ?
And are there ways to do it without compare with an item on the turtle ?
LBPHacker #2
Posted 23 October 2013 - 03:20 PM
No way of doing it without comparsion, but you dont need a stack of cobble and dirt, you only need one of both. Check if you have more than one of any of them on a secondly basis, and drop (count - 1) of them, so one block always stays in one slot of the turtle.
Kees987 #3
Posted 23 October 2013 - 03:22 PM
got a snipit of that so i dont have to invent that wheel again ? :P/>
LBPHacker #4
Posted 23 October 2013 - 03:55 PM
At the top of the code:
local function dropCrap(slot)
    local count = turtle.getItemCount(slot)
    if count < 2 then return end
    turtle.select(slot)
    turtle.drop(count - 1)
end
In the loop (you sure have a loop somewhere):
-- ... whatever code you have before this in the loop

dropCrap(1)
dropCrap(2)

-- ... whatever code you have after this in the loop
Kees987 #5
Posted 23 October 2013 - 04:01 PM
i tried this (doesn seem to work yet)
slot 2 and 3 are cobble and dirt. slot 1 is an enderchest and 16 is fuel


local function CobbleDirt()
for i=1, 16 do
  turtle.select(i)
  if turtle.compare(2) then
   if i ~= FuelSlot and i ~= EnderchestSlot and i ~= ignoreCobbleSlot and i ~= ignoreDirtSlot then
    turtle.drop()
   end
  end
  if turtle.compare(3) then
   if i ~= FuelSlot and i ~= EnderchestSlot and i ~= ignoreCobbleSlot and i ~= ignoreDirtSlot then
    turtle.drop()
   end
  end
end
end
LBPHacker #6
Posted 23 October 2013 - 04:09 PM
Heck, why did I tell you that you have to use comparsion?! I guess that was my previous idea. Okay, no need of comparsion. Just use dropCrap in the loop.
Kees987 #7
Posted 23 October 2013 - 04:13 PM
oh got it working now :D/> i used compare instead of compareTo ..


local function CobbleDirt()
for i=1, 16 do
  turtle.select(i)
  --turtle.compareTo(number slot)
  if turtle.compareTo(2) then
   if i ~= FuelSlot and i ~= EnderchestSlot and i ~= ignoreCobbleSlot and i ~= ignoreDirtSlot then
    turtle.drop()
   end
  end
  if turtle.compareTo(3) then
   if i ~= FuelSlot and i ~= EnderchestSlot and i ~= ignoreCobbleSlot and i ~= ignoreDirtSlot then
    turtle.drop()
   end
  end
end
end
Kingdaro #8
Posted 23 October 2013 - 05:30 PM
For the record, you could compress those two if statements into one using or, since they both do the same thing.

local function CobbleDirt()
for i=1, 16 do
  turtle.select(i)
  --turtle.compareTo(number slot)
  if turtle.compareTo(2) or turtle.compareTo(3) then
   if i ~= FuelSlot and i ~= EnderchestSlot and i ~= ignoreCobbleSlot and i ~= ignoreDirtSlot then
    turtle.drop()
   end
  end
end
end