Guest User

serumTest

a guest
Jul 25th, 2013
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. mg = peripheral.wrap("left")
  2.  
  3. local numSerums = 0
  4.  
  5. function checkFuel()
  6.    local f = turtle.getFuelLevel()
  7.    if (f < 10) then
  8.       turtle.turnLeft()
  9.       turtle.turnLeft()
  10.       turtle.forward()
  11.       while (f < 10) do
  12.          sleep(10)
  13.       end
  14.       turtle.turnLeft()
  15.       turtle.turnLeft()
  16.       turtle.forward()
  17.    end
  18. end
  19.  
  20. function processSerums()
  21.    local serum, state
  22.  
  23.    for serum=1,numSerums do
  24.       print ("Processing serum #"..tostring(serum))
  25.       turtle.select(serum)
  26.       turtle.drop()
  27.       repeat
  28.          sleep(5)        
  29.          state = mg.get()
  30.       until (state["Is Not Working"] and state["Energy Stored"] and state["Liquid in Tank"])
  31.       turtle.suck()
  32.    end
  33. end
  34.  
  35. function getSerums()
  36.    local serum, flag
  37.  
  38.    numSerums = 0
  39.    turtle.select(1)
  40.    
  41.    while turtle.suck() do
  42.       numSerums = numSerums + 1
  43.    end
  44. end
  45.  
  46. function doWork()
  47.    local serum
  48.    print ("Checking fuel level...")
  49.    checkFuel()
  50.    print ("Done")
  51.  
  52.    print ("Getting serums...")
  53.    turtle.turnRight()
  54.    getSerums()
  55.    turtle.turnLeft()
  56.    if (numSerums < 1) then
  57.       print ("Nothing to do!")
  58.       return
  59.    end
  60.    print ("Done")
  61.  
  62.    turtle.turnLeft()
  63.    turtle.forward()
  64.    turtle.forward()
  65.    turtle.turnRight()
  66.  
  67.    print ("Refilling serums...")
  68.    processSerums()
  69.    print ("Done")
  70.  
  71.    turtle.turnRight()
  72.    turtle.forward()
  73.    turtle.forward()
  74.    turtle.turnLeft()
  75.  
  76.    print ("Purifying serums...")
  77.    processSerums()
  78.    print ("Done")
  79.  
  80.    print ("Returning serums...")
  81.    turtle.up()
  82.    turtle.turnRight()
  83.    turtle.forward()
  84.    for serum=1,numSerums do
  85.       turtle.select(serum)
  86.       turtle.drop()
  87.    end
  88.    turtle.back()
  89.    turtle.down()
  90.    turtle.turnLeft()
  91.    print ("All done!")
  92. end
  93.  
  94. checkFuel()
  95.  
  96. while true do
  97.   os.pullEvent("redstone")
  98.   print ("Redstone event!")
  99.   local val = redstone.getBundledInput("bottom")
  100.   if (colors.test(val, colors.red)) then
  101.      print ("Start work")
  102.      doWork()
  103.      rs.setBundledOutput("bottom", colors.green)
  104.      rs.setBundledOutput("bottom", 0)
  105.   end
  106. end
Advertisement
Add Comment
Please, Sign In to add comment