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

Turtle Quarry

Started by grand_mind1, 09 December 2012 - 06:29 PM
grand_mind1 #1
Posted 09 December 2012 - 07:29 PM
Hi, I am fairly new to ComputerCraft (and programming) and I wanted to make a trurtle quarry.
This is what I have so far:

print("How many forward?")
forw= read()
print("How many down?")
down = read()
for p = 1, down do
  for i = 1, forw do
	turtle.dig()
	turtle.forward()
  end
  turtle.digDown()
  turtle.down()
  turtle.turnLeft()
  turtle.turnLeft()
  if p == down then
	for p = 1, down do
	  turtle.up()
	end
  end	
end
What it does right now is read how wide the quarry should be, how far down it should go, and then dig that area. (Keep in mind that this is just one row of the quarry. I would want to have multiple turtles next to each other running the same program) My problem is the last bit of code at the end. When it is finished I want it to return to the surface, where it started. I thought I could do this by running a for loop for as many times as I told it to go down but it doesn't seem to work. It ignores it entirely. I don't know if I am even able to do it this way or if I just derped and did something stupid.
If you have time it would be great to get some responses! Thanks! :D/>
Cranium #2
Posted 09 December 2012 - 07:36 PM

print("How many forward?")
forw= tonumber(read()) --read() returns a string. you need to convert it to a number.
print("How many down?")
down = tonumber(read())
for p = 1, down do
  for i = 1, forw do
	    turtle.dig()
	    turtle.forward()
  end
  turtle.digDown()
  turtle.down()
  turtle.turnLeft()
  turtle.turnLeft()
  if p == down then
	    for p = 1, down do
		  turtle.up()
	    end
  end  
end
You were very close. You just needed to convert the string to a number from read()
grand_mind1 #3
Posted 09 December 2012 - 07:39 PM

print("How many forward?")
forw= tonumber(read()) --read() returns a string. you need to convert it to a number.
print("How many down?")
down = tonumber(read())
for p = 1, down do
  for i = 1, forw do
		turtle.dig()
		turtle.forward()
  end
  turtle.digDown()
  turtle.down()
  turtle.turnLeft()
  turtle.turnLeft()
  if p == down then
		for p = 1, down do
		  turtle.up()
		end
  end  
end
You were very close. You just needed to convert the string to a number from read()
Thanks so much!
snoble2022 #4
Posted 10 December 2012 - 09:55 AM
Why wouldn't you just use a build craft quarry.
Doyle3694 #5
Posted 10 December 2012 - 10:13 AM
snoble, are you retarded? what if he dont use buildcraft? What if he wants to learn coding? You should think before you post.
Cranium #6
Posted 10 December 2012 - 10:55 AM
Why wouldn't you just use a build craft quarry.
Not everyone is stuck in the dark ages with Tekkit. Some people just want to have ComputerCraft.