Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- st = 0.2
- som = "Unchecked" -- State of machine
- sot = "Unkown" -- State of turtle
- ssot = "Unkown" -- SubState of turtle
- rsot = "OK" -- RunState of turtle
- oi = "None" -- Other info
- leftp = "?"
- rightp = "?"
- n = "?"
- s = "?"
- e = "?"
- w = "?"
- function r(func) -- run
- parallel.waitForAll(disp, func)
- end
- function sv(var, par) -- setvariable, to work with r() correctly
- var = par
- end
- function disp()
- term.clear()
- term.setCursorPos(1,1)
- write("Turte status: ")
- write(sot)
- term.setCursorPos(1,2)
- write("Turte substatus: ")
- write(ssot)
- term.setCursorPos(1,3)
- write("Turte runstatus: ")
- write(rsot)
- term.setCursorPos(1,4)
- write("Machine status: ")
- write(som)
- term.setCursorPos(1,5)
- write("Error Message: ")
- write(oi)
- term.setCursorPos(1,6)
- write("T = turtle ||")
- write("C = chest ||")
- write("M = machine ||")
- write("? = Unkown")
- term.setCursorPos(1,9)
- print(" "..n.." ")
- print(w.."T"..e)
- print(" "..s.." ")
- end
- function unJam()
- sot = "Unjamming output"
- turtle.select(6)
- ssot = "Getting output"
- disp()
- while cp.takeOutput() do end
- i = 6
- while i<16 do
- i = i + 1
- turtle.select(i)
- am = cp.getAtomicMass()
- nm = cp.getChemicalName()
- if am == 6 then
- if nm == "Carbon" then
- -- nothing
- else
- turtle.dropDown()
- end
- end
- end
- i = 6
- ssot = "Turning right 1/4"
- disp()
- turtle.turnRight()
- ssot = "Turning right 2/4"
- disp()
- turtle.turnRight()
- while i<16 do
- ssot = "Emptying slot "..i.."/16"
- disp()
- i = i + 1
- turtle.select(i)
- turtle.drop()
- end
- ssot = "Turning right 3/4"
- disp()
- turtle.turnRight()
- ssot = "Turning right 4/4"
- disp()
- turtle.turnRight()
- end
- function getMoreVials()
- som = "Need more vials"
- sot = "Retrieving vials"
- disp()
- a = false
- while a == false do
- sleep(st)
- turtle.select(1)
- i = 1
- while i<5 do
- ssot = "Sucking vials from top chest ("..i.."/4)"
- disp()
- a = turtle.suckUp()
- i = i + 1
- end
- turtle.select(1)
- oi = "Vials loaded: "..turtle.getItemCount(1)+turtle.getItemCount(2)+turtle.getItemCount(3)+turtle.getItemCount(4).."/256"
- if turtle.getItemCount(1)+turtle.getItemCount(2)+turtle.getItemCount(3)+turtle.getItemCount(4) == 0 then
- oi = "Not enough has been loaded. Trying again!"
- a = false
- else
- oi = "Enough loaded"
- a = true
- end
- end
- ssot = "Putting vials into machine: "
- disp()
- sleep(st)
- turtle.select(1)
- cp.putEmptyTestTube()
- turtle.select(2)
- cp.putEmptyTestTube()
- turtle.select(3)
- cp.putEmptyTestTube()
- turtle.select(4)
- cp.putEmptyTestTube()
- turtle.select(1)
- ssot = "Idle"
- end
- sot = "Starting up"
- disp()
- ssot = "Checking slots"
- disp()
- oi = "Empty slots: "
- s = 1
- for s = 1,16 do
- if turtle.getItemCount(s) == 0 then
- oi = oi..", "..s
- disp()
- else
- print()
- oi = "Slot "..s.." is not empty! Please empty all slots before starting."
- rsot = "ERROR"
- disp()
- sleep(2)
- os.reboot()
- end
- end
- print()
- ssot = "Initialising chem peripheral"
- disp()
- sleep(st)
- if peripheral.getMethods("left") == nil then
- if peripheral.getMethods("right") == nil then
- rsot = "ERROR"
- oi = "No peripherals attached!"
- sleep(2)
- os.reboot()
- elseif peripheral.getMethods("right")[1] == "getChemicalName" then
- oi = "Found chem on right"
- cp = peripheral.wrap("right")
- rightp = "P"
- else
- rsot = "ERROR"
- oi = "No valid peripherals attached!"
- sleep(2)
- os.reboot()
- end
- elseif peripheral.getMethods("left")[1] == "getChemicalName" then
- oi = "Found chem on left"
- cp = peripheral.wrap("left")
- leftp = "P"
- else
- rsot = "ERROR"
- oi = "No valid peripherals attached!"
- disp()
- sleep(2)
- os.reboot()
- end
- disp()
- ssot = "Checking if block infront"
- disp()
- if turtle.detect() == false then
- rsot = "ERROR"
- oi = "No block in front! Restart the program when there is a machine infront"
- disp()
- sleep(2)
- os.reboot()
- end
- ssot = "Checking if block infront is a machine: "
- disp()
- state = cp.getMachineState()
- sleep(st)
- while 1<2 do
- disp()
- state = cp.getMachineState()
- if state == nil then
- state = "???"
- end
- print("State of machine: "..state)
- som = state
- disp()
- if state == "needtesttubes" then
- getMoreVials()
- elseif state == "powered" then
- unJam()
- sot = "Filling machine with input"
- turtle.select(5)
- ssot = "Sucking items from chest underneath"
- disp()
- a = false
- while a == false do
- a = turtle.suckDown()
- if a then
- -- nothng
- else
- rsot = "WARNING"
- oi = "Out of input!"
- disp()
- end
- end
- rsot = "OK"
- ssot = "Inserting input items into machine"
- cp.putInput()
- ssot = "Idle"
- elseif state == "decomposing" then
- sot = "Idle"
- ssot = "Idle"
- oi = "None"
- rsot = "OK"
- elseif state == "outputjammed" then
- unJam()
- end -- state
- sleep(1)
- end -- main loop
- write("Getting decomposable item: ")
- a = false
- while a == false do
- sleep(st)
- a = turtle.suckDown()
- if a then
- --nothing
- else
- print("FAIL")
- print("Trying again!")
- end
- turtle.select(2)
- turtle.transferTo(16)
- print("Items loaded: "..turtle.getItemCount(16))
- if turtle.getItemCount(16) == 0 then
- print("No items were loaded, trying again!")
- else
- print("ok")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment