Posted 05 June 2015 - 01:57 AM
Today I wrote a script for a small tree farm to learn some lua basics and now it is stuck in a loop and I cannot figure out why.
The code is meant to run a tree farm that consists of a turtle with a sapling on 3 of its 4 sides, an enderchest beneath it, and an openblocks vacuum hopper on the side that does not have a sapling. There is a different enderchest in slot 15 that has charcoal in it and slot 16 holds saplings.
The code is meant to run a tree farm that consists of a turtle with a sapling on 3 of its 4 sides, an enderchest beneath it, and an openblocks vacuum hopper on the side that does not have a sapling. There is a different enderchest in slot 15 that has charcoal in it and slot 16 holds saplings.
--ItemSort
local function itemsort()
local n = 1
while n < 15 do
turtle.select(n)
local item = turtle.getItemDetail()
if item then
print(item.name)
if
item.name == "minecraft:sapling"
then
turtle.transferTo(16)
else
turtle.dropDown()
end
n = n + 1
else
n = n + 1
end
end
end
--Dig a Tree
local function tree()
turtle.dig()
turtle.forward()
repeat
turtle.digUp()
turtle.up()
until turtle.digUp() == false
repeat
turtle.down()
until turtle.down() == false
turtle.back()
sleep(5)
itemsort()
turtle.select(16)
turtle.place()
end
--Refuel from Enderchest
local function chestfuel()
itemsort()
end
print("Checking Fuel Level")
if turtle.getFuelLevel() < 30 then
print("Refueling")
turtle.select(15)
turtle.placeUp()
turtle.suckUp()
turtle.select(1)
turtle.refuel()
turtle.select(15)
turtle.digUp()
else
print("Good Enough")
end
--Main Script
while true do
turtle.select(1)
local success, front = turtle.inspect()
if success then
if
front.name == "minecraft:log"
then
tree()
end
elseif
front.name == "minecraft:sapling"
then
turtle.turnLeft()
else
turtle.turnLeft()
end
chestfuel()
end