I am fairly new to Lua, so excuse my noobiness :)/>
This is my first program for harvesting wood from a prebuilt farm…. It obviously needs optimizing but the main problem is
that I am receiving an error when attempting to run the code. I have no clue what I'm doing wrong. I will appreciate any criticism.
The purpose of the super large checkTree() function is because of a custom route planned for the turtle.
Spoiler
local function harvestTree()
local count=0
if turtle.detect()==true then
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.select(2)
turtle.placeDown()
turtle.select(1)
while turtle.detect() do
count=count+1
turtle.digUp()
turtle.up()
end
turtle.down(count)
else
print("No tree... Continuing")
turtle.forward()
end
end
local function checkTree()
turtle.up(6)
turtle.forward(4)
turtle.turnLeft()
turtle.forward()
harvestTree()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.turnLeft()
turtle.forward(2)
harvestTree()
turtle.turnLeft()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.foward(3)
harvestTree()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.turnLeft()
turtle.forward(2)
harvestTree()
turtle.turnLeft()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.turnRight()
turtle.forward(2)
harvestTree()
turtle.forward(2)
turtle.turnLeft()
turtle.forward(4)
turtle.down(6)
end
local function cycleCharcoal
turtle.select(16)
turtle.drop()
turtle.suckUp()
turtle.drop()
turtle.suck()
turtle.dropUp()
turtle.select(1)
end
local function takeCharcoal()
turtle.select(16)
turtle.suck()
if turtle.getFuelLevel()< 100 then
turtle.refuel(2)
else
print("No fuel needed")
end
turtle.select(1)
end
local function fillFurnace()
turtle.select(3)
for i=4, 16 do
if turtle.compareTo(i)==true
turtle.select(i)
turtle.dropDown()
turtle.select(3)
else
print("Not same")
end
end
turtle.select(1)
end
local checkSaplings()
turtle.select(2)
turtle.suck()
for i=3, 16 do
if turtle.compareTo(i)==true
turtle.select(i)
turtle.drop()
turtle.select(2)
else
print("Not same Saps")
end
end
turtle.select(1)
end
local checkLogs()
turtle.select(3)
if turtle.getItemCout<3 then
turtle.suckUp()
else
print("Enough logs")
end
for i=4, 16 do
if turtle.compareTo(i)==true
turtle.select(i)
turtle.dropUp()
turtle.select(3)
else
print("Not Logs")
end
end
turtle.select(1)
end
local function furnaceCycle()
turtle.forward()
cycleCharcoal()
turtle.back()
turtle.up()
takeCharcoal()
turtle.up()
turtle.forward()
fillFurnace()
checkSaplings()
checkLogs()
turtle.back()
turtle.down(2)
turtle.turnRight()
turtle.turnRight()
end
--Main loop
local checkTime=10
local suckCount=0
local suckTimer --=os.startTimer(1)
local harvestTimer=os.startTimer(0)
while true do
local e,p1,p2=os.pullEvent()
if e=="timer" and p1==harvestTimer then
checkTrees()
furnaceCycle()
suckTimer=os.startTimer(1)
suckCount=0
elseif e=="timer" and p1==suckTimer then
turtle.suck()
suckCount=suckCount+1
if suckCount<60 then
suckTimer=os.startTimer(10)
else
harvestTimer=os.startTimer(1)
end
end
end