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

block comparing problem

Started by DTM450, 07 April 2014 - 05:24 AM
DTM450 #1
Posted 07 April 2014 - 07:24 AM
hi im working on a 3x3 tunnel miner with a turtle which was going fine until i ran into some gravel causing the program to glitch. i need to be able to compare the block before digging so that for dirt and gravel it will use the shove and wait after digging gravel to check for more gravel and so that all other blocks use the pick
shovel assigned to the right side and pick to the left side

my code (problem in dig(), digUp() and digDown() functions)
im using the turtle.compare() instead of the turtle.compareTo() because its not working correctly
pastebin link here

function forward() turtle.forward() end
function up() turtle.up() end
function down() turtle.down() end
function left() turtle.turnLeft() end
function right() turtle.turnRight() end

function left2()
for
  m = 1, 2, 1 do
  left()
end
end

function right2()
for
  m = 1, 2, 1 do
  right()
end
end

function digDown()
if
  turtle.detectDown() == true then
  turtle.select(2)
  if
   turtle.compare() == true then
   turtle.digDown(right)
  elseif
   turtle.select(3)
   turtle.compareDown() == true then
   turtle.digDown(right)
  else
   turtle.digDown(left)
  end
end
end

function dig()
if
  turtle.detect() == true then
  turtle.select(2)
  if
   turtle.compare() == true then
   turtle.dig(right)
  elseif
   turtle.select(3)
   turtle.compare() == true then
   turtle.dig(right)
  else
   turtle.dig(left)
  end
end
end

function digUp()
if
  turtle.detectUp() == true then
  turtle.select(2)
  if
   turtle.compareUp() == true then
   turtle.digUp(right)
  elseif
   turtle.select(3)
   turtle.compare() == true then
   turtle.digUp(right)
  else
   turtle.digUp(left)
  end
end
end[/color]

function detectDown()
if
  turtle.detectDown() == false then
  turtle.select(1)
  turtle.placeDown()
end
end

function detect()
if
  turtle.detect() == false then
  turtle.select(1)
  turtle.place()
end
end

function detectUp()
if
  turtle.detectUp() == false then
  turtle.select(1)
  turtle.placeUp()
end
end

dig()
--[[
-- left side of 3x3 tunnel
dig()
forward()
left()
detectDown()
detect()
digUp()
up()
detect()
digUp()
up()
detect()
detectUp()
right2()

-- top side of 3x3 tunnel
dig()
forward()
detectUp()
digDown()
dig()
forward()
detectUp()
detect()

-- right side of 3x3 tunnel
digDown()
down()
detect()
digDown()
down()
detect()
detectDown()
left2()

-- bottom side of 3x3 tunnel
dig()
forward()
detectDown()
forward()
right()
--]]
Edited on 07 April 2014 - 05:28 AM
CometWolf #2
Posted 07 April 2014 - 07:36 AM
The pick insta breaks everything, so there's no point in using a shovel. compareTo is used to compare blocks in the turtle's inventory, not in the physical world. As for your actual problem, you seem to be using a mix of compare and it's directional equivalents in the same function.
DTM450 #3
Posted 07 April 2014 - 07:38 AM
also im not sure if im using the elseif correctly

oh i though that compare was used to compare what block was in front of the turtle with the selected block
CometWolf #4
Posted 07 April 2014 - 07:49 AM
It is, note that i was talking about compareTo. Now that you mention it, yeah your elseif usage is way off.

if condition then
  --do stuff
elseif otherCondition then
  --do other stuff
else
  --non of the above
end
DTM450 #5
Posted 07 April 2014 - 07:55 AM
ok so i changed the dig functions back to these however im not sure on how to add a check loop that will check if a block has fallen down into the path before moving

function digDown()
if
  turtle.detectDown() == true then
  turtle.digDown(left)
end
end
function dig()
if
  turtle.detect() == true then
  turtle.dig(left)
end
end
function digUp()
if
  turtle.detectUp() == true then
  turtle.digUp(left)
end
end

oh ok yeah i misread you on the compareTo

i dont suppose there is a way to log in to pastebin from the computercraft computers before uploading so that i can manage my uploads later on?
DTM450 #6
Posted 07 April 2014 - 08:20 AM
ok so i figured out the checking loop
here are the new dig functions

function digDown()
while (true) do
  if
   turtle.detectDown() == true then
   turtle.digDown(left)
  else
   break
  end
end
end
function dig()
while (true) do
  if
   turtle.detect() == true then
   turtle.dig(left)
  else
   break
  end
end
end
function digUp()
while (true) do
  if
   turtle.detectUp() == true then
   turtle.digUp(left)
  else
   break
  end
end
end

revised code on pastebin