Posted 30 June 2016 - 07:07 PM
This is a small program that will farm a plot of land dependent on how large you would want your farm. It isn't the cleanest but for a first attempt at Lua I am proud of it.
Just put the turtle in the same spot the blue wool is in the picture. It is hard to get used to but once you do, it becomes habit.
Pictures:
Pastebin Code:
local farmSize = tonumber(io.read())
timeSleep = 80
while true do
function Startup1()
turtle.up()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
function Startup2()
turtle.up()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
function Farm()
for i=1,farmSize,1 do
turtle.forward()
turtle.digDown()
turtle.placeDown()
end
end
function LeftTurn()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
function RightTurn()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
function Rest()
turtle.down()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
end
Startup1()
for i=1,farmSize/2,1 do
Farm()
LeftTurn()
Farm()
RightTurn()
end
Rest()
sleep(80*60)
Startup2()
for i=1,farmSize/2,1 do
Farm()
RightTurn()
Farm()
LeftTurn()
end
Rest()
end
A few notes about the code:
-The turtle doesn't know when the wheat is fully grown or not so when it is time to harvest nothing is safe.
-The turtle is on a timer of 80 minuets between harvests.
-Fuel the turtle before using the program, I haven't added an auto refill.
-You may want to run the code a few times so you can find the best spots to put the water, as you can see just eyeballing it in the picture did not work out.
Just put the turtle in the same spot the blue wool is in the picture. It is hard to get used to but once you do, it becomes habit.
Pictures:
Spoiler
Pastebin Code:
pastebin get jexkZWTC Farm
Spoiler
print("How large do you want your farm? *Stay away from odd numbers!*")local farmSize = tonumber(io.read())
timeSleep = 80
while true do
function Startup1()
turtle.up()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
function Startup2()
turtle.up()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
function Farm()
for i=1,farmSize,1 do
turtle.forward()
turtle.digDown()
turtle.placeDown()
end
end
function LeftTurn()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
function RightTurn()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
function Rest()
turtle.down()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
end
Startup1()
for i=1,farmSize/2,1 do
Farm()
LeftTurn()
Farm()
RightTurn()
end
Rest()
sleep(80*60)
Startup2()
for i=1,farmSize/2,1 do
Farm()
RightTurn()
Farm()
LeftTurn()
end
Rest()
end
A few notes about the code:
-The turtle doesn't know when the wheat is fully grown or not so when it is time to harvest nothing is safe.
-The turtle is on a timer of 80 minuets between harvests.
-Fuel the turtle before using the program, I haven't added an auto refill.
-You may want to run the code a few times so you can find the best spots to put the water, as you can see just eyeballing it in the picture did not work out.