Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- event = require("event")
- robot = require("robot")
- term = require("term")
- component = require("component")
- local farmSize = "exit"
- local X = 1
- local function display(t)
- io.write(t)
- os.sleep(1)
- end
- local function askSize()
- term.clear()
- term.setCursor(1,1)
- io.write("How large does the farm need to be?\nType 'exit' if you want to exit the program.\n")
- farmSize = io.read()
- if farmSize == "exit" then
- os.exit()
- elseif type(tonumber(farmSize)) == "number" then
- if farmSize % 2 == 0 then
- display("Working on it!")
- term.clear()
- else
- display("Please enter an even number!")
- askSize()
- end
- else
- display("Please enter a number.")
- askSize()
- end
- term.clear()
- end
- local function getSeeds()
- repeat local y = robot.suckDown()
- until y == false
- end
- local function check()
- robot.useDown()
- getSeeds()
- robot.forward()
- end
- local function checkX(n)
- for i=1, n do
- check()
- end
- end
- local function turnRight()
- robot.turnRight()
- robot.forward()
- robot.turnRight()
- robot.forward()
- X = 1
- end
- local function turnLeft()
- robot.turnLeft()
- robot.forward()
- robot.turnLeft()
- robot.forward()
- X = 0
- end
- local function turn()
- if X==0 then
- turnRight()
- else
- turnLeft()
- end
- end
- local function size(n)
- for i=1, n do
- checkX(n)
- turn()
- end
- end
- local function dropOff()
- for i=1, 16 do
- robot.select(i)
- robot.dropDown()
- end
- end
- local function exitFarm()
- local c = 0
- term.clear()
- term.setCursor(1,1)
- io.write("Press 'e' to exit during the cool down period!")
- local a, b, c, d = event.pull(60, "key_down")
- if c ~= nil then
- if string.char(c) == "e" then
- term.clear()
- term.setCursor(1,1)
- display("Exitting!\n")
- os.exit()
- else
- os.sleep(60)
- end
- end
- term.clear()
- end
- term.clear()
- term.setCursor(1,1)
- display("Farming robot v.2\n")
- askSize()
- io.write("Farming...")
- local S = tonumber(farmSize)
- while true do
- robot.forward()
- size(S)
- robot.turnRight()
- checkX(S)
- robot.turnLeft()
- robot.back()
- dropOff()
- exitFarm()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement