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

So Confused..

Started by Mikev619619, 30 March 2013 - 05:36 PM
Mikev619619 #1
Posted 30 March 2013 - 06:36 PM
Alright so I wrote this progam here to make me a 3X3 tunnel the way i would want the turtle to mine It.
It works perfectly fine and deals with gravel except…if there a block missing? so if there no block for it to dig it will go an extra forward and the tunnel will be all messed up any idea why?

Code:

function Gravel()
sleep(.6)
  if turtle.forward() == false then
   repeat turtle.dig() until
   turtle.forward() == true
else
  turtle.forward()
end
end

function First()
turtle.dig()
Gravel()
turtle.turnRight()
turtle.digUp()
turtle.up()
turtle.digUp()
end

function Seconed()
turtle.dig()
Gravel()
turtle.digUp()
turtle.digDown()
end

function Left()
turtle.turnLeft()
Gravel()
turtle.turnLeft()
turtle.digUp()
turtle.digDown()
end

function LayerOne()
First()
Seconed()
Seconed()
end

function LayerTwo()
firstSecond()
Seconed()
Seconed()
end

function firstSecond()
turtle.dig()
Gravel()
turtle.turnRight()
turtle.digUp()
turtle.digDown()
end

function Final()
LayerOne()
Left()
Seconed()
Seconed()
turtle.turnRight()
end

function FinalTwo()
LayerTwo()
Left()
Seconed()
Seconed()
turtle.turnRight()
end

Final()
for i = 1,32 do
FinalTwo()
end

Thanks, Mike :lol:/>
theoriginalbit #2
Posted 30 March 2013 - 06:41 PM
it is because of the logic you use here

function Gravel()
  sleep(.6)
  if turtle.forward() == false then
	repeat turtle.dig()
	until turtle.forward() == true
  else
	turtle.forward()
  end
end
what this does is this

>> move the turtle
>>> if it did not move, then dig and move
>>> if it did move then, move it again <<<< here is your problem.

the simplest fix is to remove the else statement however do this

function Gravel()
  while turtle.detect() do
	if not turtle.dig() then
	  printError("I cannot dig this block... Is it bedrock?")
	end
	sleep(0.8) -- falling speed of blocks in Minecraft
  end
  if not turtle.forward() then
	if not turtle.attack() then
	  printError("Out of fuel?")
	else
	  printError("A mob is in my way")
	end
  end
end
that way instead of using a movement function to see if it needs to dig, it just looks if there is a block there.
faubiguy #3
Posted 30 March 2013 - 06:43 PM
From looking at this, it appears that the turtle moves forward in the
if turtle.forward() == false then
and again in the else block since it moved =, and therefore wasn't false. So you should try removeing the else in Gravel

Edit: Ninja'd
Mikev619619 #4
Posted 30 March 2013 - 08:10 PM
With reading your post I came up with this even though it might not be the most affective way, but it works.

Code:

function Gravel()
  if turtle.detect() == true then
   repeat turtle.dig() until
   turtle.detect() == false
end

end
function G2()
sleep(.6)
if turtle.forward() == false then
  repeat Gravel() until
  turtle.forward() == true
end
end


LordIkol #5
Posted 31 March 2013 - 12:58 AM
Why you not use sth like


local function goForward()
while not moved do
turtle.dig()
sleep(0.8) --just to be sure gravel or sand has time to fall down 
moved = turtle.forward()
end
end

Greets loki