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

Working lumberjack

Started by greenbuilderman, 14 October 2012 - 02:35 PM
greenbuilderman #1
Posted 14 October 2012 - 04:35 PM
Hello I have recently rewritten the code for the lumberjack from the wiki. I have not copied it in any way but I have made one that does the same thing as the advanced one

Spoiler
term.clear()
term.setCursorPos(1,1)
print"Lumberjack 1.0"
print"Type 'exit' to exit program."
term.setCursorPos(1,4)
print"System: To start, please put dirt in slot 1, saplings in slot 2(Preferred not to be oak), and wood of the same type in slot 3."
print("System: When you do that, please enter the amount of trees to plant. Oh and remember, my fuel tank is at " .. turtle.getFuelLevel() .. ".")

write"You: "

local txt = io.read()

-- if exit then restart--
if txt == "exit" then
  os.reboot()
end
local dirt, sapling, wood = 1, 2, 3, 4
num = txt
tree = 0

print("System: Now planting " .. num .. " trees")

--Planting trees--
turtle.up()
turtle.down()
turtle.turnRight()
for i = 1, num do
  if turtle.detectDown() == false then
    turtle.select(dirt)
    turtle.placeDown()
  end
  turtle.back()
  turtle.select(sapling)
  turtle.place()
  turtle.turnLeft()
  turtle.forward()
  turtle.forward()
  turtle.forward()
  turtle.forward()
  turtle.turnRight()
  turtle.forward()
end

print("System: " .. num .. " trees were planted.")

--get back into position--
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()

-- tree harvesting--
while true do
  sleep(30)
  for i = 1, num do
    turtle.turnRight()
    turtle.select(wood)
    if turtle.compare() == true then
      turtle.dig()
      turtle.forward()
      while turtle.detectUp() do
        turtle.digUp()
        turtle.up()
      end
      while not turtle.detectDown() do
        turtle.down()
      end
      turtle.back()
      turtle.select(sapling)
      turtle.place()
      tree = tree + 1
      print("System: " .. tree .. " trees were harvested.")
    end
    turtle.turnLeft()
    turtle.forward()
    turtle.forward()
    turtle.forward()
    turtle.forward()
  end
  turtle.turnRight()
  turtle.forward()
  turtle.forward()
  turtle.turnRight()
  turtle.forward()
  turtle.forward()
  turtle.forward()
  turtle.forward()
  print"System: Finished Checking trees."
end

you can download the file, take away the extention, and put it in \computercraft.zip\lua\rom\programs\turtle\lumberjack. If you do that it'll be on all turtles!
slango20 #2
Posted 15 October 2012 - 01:19 AM
You can use: if not turtle.detectDown then instead of if turtle.detectDown == false then