Guest User

serumTest3

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