Guest User

serumRefill

a guest
Aug 13th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. mg = peripheral.wrap("left")
  2. rednet.open("right")
  3.  
  4. local numSerums = 0
  5.  
  6. function processSerums()
  7.    local serum, state
  8.    
  9.    for serum=1,numSerums do
  10.       print ("Processing serum #"..tostring(serum))
  11.       turtle.select(serum)
  12.       turtle.drop()
  13.       sleep(1)
  14.       state = mg.get()
  15.      
  16.       if (state["Full Serum"] == false) then
  17.          repeat
  18.             sleep(25)
  19.             state = mg.get()
  20.          until (state["Full Serum"] == true)
  21.       end
  22.      
  23.       turtle.suck()
  24.    end
  25. end
  26.  
  27. function getSerums()
  28.    local serum, flag
  29.    
  30.    numSerums = 0
  31.    turtle.select(1)
  32.    
  33.    while turtle.suck() do
  34.       numSerums = numSerums + 1
  35.    end
  36. end
  37.  
  38. function doWork()
  39.    print ("Getting serums...")
  40.    turtle.turnLeft()
  41.    getSerums()
  42.    turtle.turnRight()
  43.    if (numSerums < 1) then
  44.       print ("Nothing to do!")
  45.       return
  46.    end
  47.    print ("Done")
  48.    
  49.    print ("Processing serums...")
  50.    processSerums()
  51.    print ("Done")
  52.    
  53.    print ("Returning serums...")
  54.    turtle.turnRight()
  55.    for serum=1,numSerums do
  56.       turtle.select(serum)
  57.       turtle.drop()
  58.    end
  59.    turtle.turnLeft()
  60.    print ("All done!")
  61. end
  62.  
  63. while true do
  64.    id, msg, dist = rednet.receive()
  65.    if (msg == "Refill") and ((dist == 4) or (dist == 7)) then
  66.       print ("Start work")
  67.       sleep(1)
  68.       doWork()
  69.       rednet.broadcast("Purify")
  70.    end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment