Difference between revisions of "Advanced Turtle Lumberjack (tutorial)"

From ComputerCraft Wiki
Jump to: navigation, search
(Bent Abacus)
(Another Advanced Turtle Lumberjack)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
I requisite to allocate this site I initiate when looking quest of diminish auto parts, they saved me 100s of dollars when I was getting my motor car back on the technique form month, so I thought I'd restore the karma and entrust them a do away with on here. Usually 'mark-down auto parts' turn at large to be anything but, and you tip up spending over-the-odds as a replacement for miserable quality parts and yeah, that's no longer a mistake I can have the means to make, who can in this concision, right? So, rpm-motots-inc.com are rare, like exceptionally, indeed different. Elementary up, the quotation you are quoted is the quotation you pay off, no arcane extras. The parts I ordered were all in dynasty, were shipped fasting and were well packaged. I was amazed with the distinction, especially instead of the low fee I paid, which was
+
 
$391 cheaper than the accessible allowance auto parts sites. I had a scarcely any questions before I ordered and the crook I spoke to were bloody beneficial, and knew their stuff. Their purchaser care and range of parts is arousing, rpm motors certainly nurture their promises when it comes to discount auto parts.
+
== Advanced Turtle Lumberjack ==
 +
=== Introduction ===
 +
Welcome to this [[:Category:Tutorials|tutorial]] about Advanced Turtle Lumberjacks.
 +
See the [[Turtle_Lumberjack_(tutorial)|Turtle Lumberjack Tutorial]] first.
 +
 
 +
=== What are Advanced Turtle Lumberjacks? ===
 +
Advanced Turtle Lumberjacks are basically [[Turtle_Lumberjack_(tutorial)|Turtle Lumberjacks]] that can dig blocks above them. We first make the turtle dig the block in front of it and then move forward so the rest of the tree is directly above it.
 +
 
 +
== The Code ==
 +
<code>
 +
  turtle.dig()
 +
  turtle.forward()
 +
  while turtle.detectUp() do
 +
    turtle.digUp()
 +
    turtle.up()
 +
  end
 +
  while not turtle.detectDown() do
 +
    turtle.down()
 +
  end
 +
</code>
 +
This makes us check if there are no blocks to be dug, then we go down until we can't.
 +
That's it!
 +
 
 +
-----------------------------------------------------------------------------------------
 +
 
 +
== Another Advanced Turtle Lumberjack ==
 +
 
 +
This is a lot more complex BUT this can create a row of trees and constantly monitor them to see if they have grown or not. Here is a link to a video showing what it does- [http://www.youtube.com/watch?v=7rmB09b6wYk ComputerCraft-Turtle-Tree Lumberjack]
 +
<code>
 +
-- advanced turtle lumberjack
 +
shell.run('clear')
 +
print("Please put Dirt in Slot 1, Saplings in Slot 2, and a log in Slot 3.")
 +
print("Number of Trees To Plant?")
 +
local x = io.read()
 +
local dirt, sapling, log = 1, 2, 3
 +
 +
-- get into position
 +
turtle.up()
 +
turtle.turnLeft()
 +
turtle.turnLeft()
 +
turtle.back()
 +
turtle.back()
 +
turtle.back()
 +
 +
-- initial planting
 +
for i = 0, x do
 +
  turtle.digDown()
 +
  turtle.select(dirt)
 +
  turtle.placeDown()
 +
  turtle.back()
 +
  turtle.select(sapling)
 +
  turtle.place()
 +
  turtle.back()
 +
  turtle.back()
 +
  turtle.back()
 +
end
 +
turtle.turnLeft()
 +
turtle.forward()
 +
turtle.turnRight()
 +
 +
--chop trees
 +
while true do
 +
  -- sleep for 30 seconds
 +
  os.sleep(30)
 +
  -- check all trees for any that have grown
 +
  for i = 0, x do
 +
    turtle.forward()
 +
    turtle.forward()
 +
    turtle.forward()
 +
    turtle.forward()
 +
    turtle.turnRight()
 +
    turtle.select(log)
 +
    -- if the tree has grown
 +
    if turtle.compare() then
 +
      turtle.dig()
 +
      turtle.forward()
 +
      -- harvest the tree
 +
      while turtle.detectUp() do
 +
      turtle.digUp() 
 +
      turtle.up()
 +
      end
 +
      -- return to the ground
 +
      while not turtle.detectDown() do
 +
        turtle.down()
 +
      end
 +
      -- plant a new sapling
 +
      turtle.back()
 +
      turtle.select(sapling)
 +
      turtle.place()
 +
    end
 +
    turtle.turnLeft()
 +
  end
 +
  -- round the corner
 +
  turtle.forward()
 +
  turtle.turnRight()
 +
  turtle.forward()
 +
  turtle.forward()
 +
  turtle.turnRight()
 +
  turtle.forward()
 +
end
 +
</code>
 +
 
 +
 
 +
('''Helpful tip:''' Save this to your computercraft/lua/rom/programs folder, then it will be on all turtles.)
 +
 
 +
== Simplified Advanced Turtle Lumberjack ==
 +
This is a simplified version of an advanced turtle lumberjack.  As the header comment states, it assumes that the turtle is in the bottom left corner of a 10x3 flat area of dirt and a stack of saplings is in slot 1.  This will run until it runs out of fuel, or it has planted all the saplings.  See [https://github.com/noctolater/Turtles this github repository] for this and other automatic turtle related programs.
 +
 
 +
<code>
 +
--[[ Simple lumberjack program for the wiki. Assumes the turtle is in the
 +
bottom left corner of a 10 ahead and 3 to the right area of clear dirt or
 +
grass.  Also, only works for oak saplings, since they can grow next to each
 +
other. ]]--
 +
local saplings = 1 -- the slot where the saplings are
 +
turtle.select(saplings) -- select the saplings
 +
while turtle.getItemCount(saplings) > 0 do -- while more saplings in inventory
 +
for i = 1, 8 do -- plant 8 saplings in a row
 +
turtle.turnRight()
 +
if not turtle.compare() then -- if not a sapling, then a tree grew
 +
turtle.dig()
 +
turtle.forward()
 +
while turtle.detectUp() do -- dig tree out
 +
turtle.digUp()
 +
turtle.up()
 +
end
 +
while not turtle.detectDown() do -- back down to ground
 +
turtle.down()
 +
end
 +
turtle.back()
 +
turtle.place() -- put down new sapling
 +
end
 +
turtle.turnLeft()
 +
turtle.forward()
 +
end
 +
-- turn around and line up for next pass
 +
turtle.turnRight()
 +
turtle.forward()
 +
turtle.forward()
 +
turtle.turnRight()
 +
turtle.forward()
 +
os.sleep(30) -- sleep for 30 seconds to allow trees to grow
 +
end
 +
</code>
 +
[[Category:Tutorials]]

Latest revision as of 19:19, 23 September 2012

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. We first make the turtle dig the block in front of it and then move forward so the rest of the tree is directly above it.

The Code

 turtle.dig()
 turtle.forward()
 while turtle.detectUp() do
   turtle.digUp()
   turtle.up()
 end
 while not turtle.detectDown() do
   turtle.down()
 end

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


Another Advanced Turtle Lumberjack

This is a lot more complex BUT this can create a row of trees and constantly monitor them to see if they have grown or not. Here is a link to a video showing what it does- ComputerCraft-Turtle-Tree Lumberjack

-- advanced turtle lumberjack
shell.run('clear')
print("Please put Dirt in Slot 1, Saplings in Slot 2, and a log in Slot 3.")
print("Number of Trees To Plant?")
local x = io.read()
local dirt, sapling, log = 1, 2, 3

-- get into position
turtle.up()
turtle.turnLeft()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.back()

-- initial planting
for i = 0, x do
  turtle.digDown()
  turtle.select(dirt)
  turtle.placeDown()
  turtle.back()
  turtle.select(sapling)
  turtle.place()
  turtle.back()
  turtle.back()
  turtle.back()
end
turtle.turnLeft()
turtle.forward()
turtle.turnRight()

--chop trees
while true do
  -- sleep for 30 seconds
  os.sleep(30)
  -- check all trees for any that have grown
  for i = 0, x do
    turtle.forward()
    turtle.forward()
    turtle.forward()
    turtle.forward()
    turtle.turnRight()
    turtle.select(log)
    -- if the tree has grown
    if turtle.compare() then
      turtle.dig()
      turtle.forward()
      -- harvest the tree
      while turtle.detectUp() do
      turtle.digUp()  
      turtle.up()
      end
      -- return to the ground
      while not turtle.detectDown() do
        turtle.down()
      end
      -- plant a new sapling
      turtle.back()
      turtle.select(sapling)
      turtle.place()
    end
    turtle.turnLeft()
  end
  -- round the corner
  turtle.forward()
  turtle.turnRight()
  turtle.forward()
  turtle.forward()
  turtle.turnRight()
  turtle.forward()
end


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

Simplified Advanced Turtle Lumberjack

This is a simplified version of an advanced turtle lumberjack. As the header comment states, it assumes that the turtle is in the bottom left corner of a 10x3 flat area of dirt and a stack of saplings is in slot 1. This will run until it runs out of fuel, or it has planted all the saplings. See this github repository for this and other automatic turtle related programs.

--[[ Simple lumberjack program for the wiki.  Assumes the turtle is in the 
	bottom left corner of a 10 ahead and 3 to the right area of clear dirt or
	grass.  Also, only works for oak saplings, since they can grow next to each
	other. ]]--
local saplings = 1 -- the slot where the saplings are
turtle.select(saplings) -- select the saplings
while turtle.getItemCount(saplings) > 0 do -- while more saplings in inventory
	for i = 1, 8 do -- plant 8 saplings in a row
		turtle.turnRight()
		if not turtle.compare() then -- if not a sapling, then a tree grew
			turtle.dig()
			turtle.forward()
			while turtle.detectUp() do -- dig tree out
				turtle.digUp()
				turtle.up()
			end
			while not turtle.detectDown() do -- back down to ground
				turtle.down()
			end
			turtle.back()
			turtle.place() -- put down new sapling
		end
		turtle.turnLeft()
		turtle.forward()
	end
	-- turn around and line up for next pass
	turtle.turnRight()
	turtle.forward()
	turtle.forward()
	turtle.turnRight()
	turtle.forward()
	os.sleep(30) -- sleep for 30 seconds to allow trees to grow
end