Advanced Turtle Lumberjack (tutorial)

From ComputerCraft Wiki
Revision as of 14:25, 26 February 2012 by TheVarmari (Talk | contribs) (Created page with " == Advanced Turtle Lumberjack == === Introduction === Welcome to this tutorial about Advanced Turtle Lumberjacks. See the [[Turtle_Lumberjack_(tutoria...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Advanced Turtle Lumberjack

Introduction

Welcome to this tutorial about Advanced Turtle Lumberjacks. See the Turtle Lumberjack Tutorial first.

What are Advanced Turtle Lumberjacks?

Advanced Turtle Lumberjacks are basically Turtle Lumberjacks that can dig blocks above them.

The Code

First, we start with the basics.

while turtle.detect() do

end

This makes us loop until there is no blocks in front of the turtle.

while turtle.detect() do
 turtle.dig()
end

This makes it dig the block. Now we make it see if there is a block ABOVE it.

while turtle.detect() do
 turtle.dig()
  if turtle.detectUp()
   turtle.digUp()
  end
end

This makes us dig the block above if there is one. Let's make us move up.

while turtle.detect() do
 turtle.dig()
  if turtle.detectUp()
   turtle.digUp()
 turtle.up()
  end
end

Now, let's make it come back down when there is no blocks to be digged.

while turtle.detect() do
 turtle.dig()
  if turtle.detectUp()
   turtle.digUp()
 turtle.up()
  end
end
while not turtle.detect() and not turtle.detectUp() and turtle.detectDown() do
 turtle.down()
end

This makes us check if there are no blocks to be digged, then we go down until we can't. That's it!

(Helpful tip: Save this to your computercraft/lua/programs folder, then it will be on all turtles.)

Category & Author

A tutorial by TheVarmari. Feel free to correct any mistakes!