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

Turtle counting blocks moved or something?

Started by Jim, 17 January 2014 - 08:52 AM
Jim #1
Posted 17 January 2014 - 09:52 AM
Hello ComputerCrafters!,

Let's say I've got a jungle tree. I have put a turtle in front of the left bottom block of it. I have programmed the turtle to chop it's way up until
turtle.detectUp() == false


My problem is that, I want it to go ahead and chop down the second row of it as well. I have set it up turning, but I want it to chop its way down exactly as many blocks as the ammount of blocks chopped up (In a single row). I have tried
turtle.compare()
or
turtle.compareDown()
, but the problem is that there sometimes are leaves under/in front of the turtle, sometimes not. This may be a simple thing to do, but I am very new to programming and Lua, so any help would be appreciated.

Anyone got any idea(s)?
Edited on 17 January 2014 - 08:55 AM
wieselkatze #2
Posted 17 January 2014 - 10:03 AM
If your setup looks like this:
J = Jungle Tree Wood
T = Turtle

J J T
J J

You could just write sth. like this:


blocksTravelled = 0
turtle.dig()
turtle.forward()
while turtle.detect() do
turtle.dig()
  if turtle.detectUp() then
  turtle.digUp()
  end
turtle.up()
blocksTravelled = blocksTravelled + 1 -- Every time it goes 1 up this adds 1
end
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
for i = 1, blocksTravelled do
turtle.digDown()
turtle.dig()
turtle.down()
end
turtle.dig()

Pretty basic (not tested)
Edited on 17 January 2014 - 09:04 AM
Jim #3
Posted 17 January 2014 - 10:12 AM
Works like a charm! Thanks a ton, buddy!

I had something exactly like this in mind, I just couldn't get it syntaxed properly. Thanks again!