Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables:
- local firstTimeSetup = "yes"
- local taskDone = "yes"
- local task = "waiting"
- local waitTime = 30
- local waitTimeMax = 300
- local emptyCount
- local varStorage = {}
- --Functions:
- function storeVariables()
- varStorage.task = task
- varStorage.taskDone = taskDone
- --The above stores the variables in the table
- local output = textutils.serialize(varStorage)
- --This converts the table to a string
- local handle = assert(fs.open("vars", "w"), "Couldn't save vars")
- handle.write(output)
- handle.close()
- end
- function getVariables()
- local handle = assert(fs.open("vars", "r"), "Couldn't load vars")
- local input = handle.readAll()
- handle.close()
- local destination = textutils.unserialize(input)
- task = destination.task
- taskDone = destination.taskDone
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function getBat()
- task = "gettingBattery"
- taskDone = "no"
- storeVariables()
- turtle.select(1)
- turtle.suck()
- emptyCount = turtle.getItemCount(1)
- if emptyCount == 0 then print("No more than 0")
- while emptyCount == 0 do
- turtle.select(1)
- turtle.suck()
- emptyCount = turtle.getItemCount(1)
- sleep(waitTime)
- end
- end
- if emptyCount > 0 then print("Got more than 0")
- if emptyCount == 1 then print("Got 1") elseif emptyCount > 1 then print("More than 1")
- emptyCount = emptyCount - 1
- turtle.drop(emptyCount)
- end
- end
- taskDone = "yes"
- end
- function putBat()
- task = "puttingBattery"
- taskDone = "no"
- storeVariables()
- turtle.select(1)
- turtle.dropUp()
- taskDone = "yes"
- end
- function wait()
- task = "waiting"
- taskDone = "no"
- storeVariables()
- sleep(waitTime)
- taskDone = "yes"
- end
- function waitMax()
- task = "waiting"
- taskDone = "no"
- storeVariables()
- sleep(waitTimeMax)
- taskDone = "yes"
- end
- function pickUp()
- task = "pickingUp"
- taskDone = "no"
- storeVariables()
- turtle.select(1)
- turtle.digDown()
- taskDone = "yes"
- end
- function place()
- task = "placing"
- taskDone = "no"
- storeVariables()
- turtle.select(1)
- turtle.placeDown()
- taskDone = "yes"
- end
- function operation()
- pickUp()
- putBat()
- getBat()
- place()
- wait()
- waitMax()
- end
- --Main Program:
- --First startup run:
- if firstTimeSetup == "yes" then
- clear()
- print("Don't forget to change the *firstTimeSetup = 'yes'* variable to 'no'!")
- print("Do this by typing 'edit FileName'")
- print("(FileName = what you named the program)")
- print("into the console after reboot.")
- print()
- textutils.slowPrint("Saving StartUp variables...")
- print()
- print()
- term.write("Press any key to reboot:") io.read()
- storeVariables()
- sleep(1)
- os.reboot()
- end
- --StartUp:
- getVariables()
- if task == "pickingUp" then
- if taskDone == "yes" then
- putBat()
- getBat()
- place()
- wait()
- waitMax()
- elseif taskDone == "no" then
- pickUp()
- putBat()
- getBat()
- place()
- wait()
- waitMax()
- end
- elseif task == "puttingBattery" then
- if taskDone == "yes" then
- getBat()
- place()
- wait()
- waitMax()
- elseif taskDone == "no" then
- putBat()
- getBat()
- place()
- wait()
- waitMax()
- end
- elseif task == "gettingBattery" then
- if taskDone == "yes" then
- place()
- wait()
- waitMax()
- elseif taskDone == "no" then
- getBat()
- place()
- wait()
- waitMax()
- end
- elseif task == "placing" then
- if taskDone == "yes" then
- wait()
- waitMax()
- elseif taskDone == "no" then
- place()
- wait()
- waitMax()
- end
- elseif task == "waiting" then
- if taskDone == "no" then
- wait()
- end
- end
- --End of StartUp
- while true do
- operation()
- end
Advertisement
Add Comment
Please, Sign In to add comment