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

Turtle Detecting Program Help

Started by Adjgamer, 24 January 2013 - 04:47 PM
Adjgamer #1
Posted 24 January 2013 - 05:47 PM
So I am writing a program for a turtle tree farm and I want my turtle to dig up until turtle.detectUp() == false
this is what i am thinking:

function uptill()
	 while turtle.detectUp() == true do
		  turtle.digUp()
		  turtle.up()
	 until turtle.detectUp() == false
--[ at which point i want it to come back down until turtle.detectDown == true ]--
Cranium #2
Posted 24 January 2013 - 05:52 PM

local height = 0
while turtle.detectUp() do
  turtle.digUp()
  turtle.up()
  height = height + 1
end
repeat
  turtle.down()
  height = height - 1
until height == 0
That should work for you!
theoriginalbit #3
Posted 24 January 2013 - 05:57 PM

local height = 0
while turtle.detectUp() do
  turtle.digUp()
  turtle.up()
  height = height + 1
end
repeat
  turtle.down()
  height = height - 1
until height == 0
That should work for you!
why not just this since a tree can only grow on a block

while turtle.detectUp() do
  turtle.digUp()
  turtle.up()
end
while turtle.down()
end
Cranium #4
Posted 24 January 2013 - 06:01 PM
That may be true, but I always like to count how far I have traveled. It helps me figure out where I can add in additional code, such as detecting more leaves, or other things. Just a personal preference.
Adjgamer #5
Posted 24 January 2013 - 06:04 PM

local height = 0
while turtle.detectUp() do
  turtle.digUp()
  turtle.up()
  height = height + 1
end
repeat
  turtle.down()
  height = height - 1
until height == 0
That should work for you!

Thanks :D/> That counting how far up then going down that many was a good idea! Never would have thought of it ;)/>