Posted 11 January 2013 - 08:27 PM
I am making an automatic farmer and one of my loops keeps going infinitely it seems.
Pretty sure this is the code causing problems but I will post all of it just in case.
All the code.
Pretty sure this is the code causing problems but I will post all of it just in case.
function harv(length,width,p)
gofwd(length,true)
turtle.turnRight()
gofwd(1,true)
turtle.turnRight()
local i = 1
repeat
gofwd(length-1,true)
lor(i)
gofwd(1,true)
lor(i)
i = i + 1
until i == width
if p == true then
plant(length,width)
end
end
All the code.
local args = {...}
local L = args[1]
local W = args[2]
local Pl = args[3]
function seedsel()
local i = 1
repeat
i = i + 1
until turtle.getItemCount(i) > 0
return i
end
function gofwd(steps,dig)
local i = 1
repeat
if dig == true then
turtle.dig()
end
turtle.forward()
i = i + 1
until i == steps + 1
end
function gobck(steps,dig)
local i = 1
repeat
turtle.back()
if dig == true then
turtle.dig()
turtle.select(seedsel)
turtle.place()
end
i = i + 1
until i == steps + 1
end
function lor(num)
if num % 2 == 0 then
turtle.turnRight()
else
turtle.turnLeft()
end
end
function harv(length,width,p)
gofwd(length,true)
turtle.turnRight()
gofwd(1,true)
turtle.turnRight()
local i = 1
repeat
gofwd(length-1,true)
lor(i)
gofwd(1,true)
lor(i)
i = i + 1
until i == width
if p == true then
plant(length,width)
end
end
function plant(length,width)
turtle.turnRight()
turtle.turnRight()
local i = 1
repeat
gobck(length-1,true)
lor(i)
gobck(1,true)
lor(i)
i = i + 1
until i == width
gobck(length,true)
end
function fuelcheck()
local fuelReq = L * W * 2
if turtle.getFuelLevel() < fuelReq then
print("Not enough fuel. Required fuel is "..fuelReq..".")
return false
else
return true
end
end
function seedcheck()
local seedsreq = L * W
print("Please place "..seedsreq.." into the inventory. Then press ENTER")
local r = read("*")
end
if fuelcheck() then
seedcheck()
print("Harvesting the "..L.." x "..W.." area.")
harv(L,W,Pl)
end