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

Custom Dimensions Tunnel with Turtle

Started by ADancingClown, 24 December 2012 - 09:29 AM
ADancingClown #1
Posted 24 December 2012 - 10:29 AM
Hey,
So I'm really new to computercraft and I'm using it in Feed The Beast. Basically, I'm trying to write a turtle program that will allow me to specify the dimensions of a tunnel and have the turtle dig it. The variable d is for the length of the tunnel (distance), the variable h is for the height of the tunnel, and the variable w is for the width of the tunnel. Any input on how to make it work would be much appreciated! My current problem is when I run the program, the input screen for distance, width and height comes up, I put in the values I want, and then the turtle takes off in one direction and just keeps digging. :(/>

--- Dimensional Input ---

term.clear()
textutils.slowPrint("Distance?")
  local d=io.read()
  d=tonumber(d)
textutils.slowPrint("Height?")
  local h=io.read()
  h=tonumber(h)
textutils.slowPrint("Width?")
  local w=io.read()
  w=tonumber(w)

--- Feedback ---

term.clear()
print("Digging a tunnel that is")
print((w)," blocks wide,")
print((h)," blocks tall,")
print("and ",(d)," blocks long")

--- Digging ---

while d > 0 do
  turtle.select(1)
  turtle.refuel(64)
  turtle.dig()
  turtle.forward()

--- Width ---

  function width(w)
	local e = w
	   if e > 1 then do
		  turtle.turnRight()
		  turtle.dig()
		  turtle.forward()
		  turtle.turnLeft()
		  e = e - 1
	end
	width(w)
	turtle.turnLeft()
	turtle.forward(w)
	turtle.turnRight()
  end

--- Height ---

  Functionname=height()
	local j = h
	  if j > 1 then do
		 turtle.digup()
		 turtle.up()
		 j = j - 1
	  end
	  turtle.down(h)
  end
	local e = w
	  if e > 1 then do
		 turtle.turnRight()
		 turtle.forward()
		 turtle.turnLeft()
		 height()
		 turtle.down(h)
		 e = e - 1
	end
	turtle.turnLeft()
	turtle.forward(w)
	turtle.turnRight()
  end
  d = d - 1
end
end
Orwell #2
Posted 24 December 2012 - 10:44 AM
You don't ever call width() except from within the function itself. Also, this line doesn't make much sense, why don't you just do 'function height()' like earlier?:

  Functionname=height()
And finally, the function turtle.forward() doesn't take any parameters. So this:

turtle.forward(w)
Will go exactly one block forward and is the same as this:

turtle.forward()

That's what I could spot real quick. Update those parts and if you still have those problems (probably), then post your full code again.