Advertisement
Guest User

startup

a guest
Apr 21st, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. rednet.open("right")
  2. local prevLiquid = -1
  3.  
  4. function place()
  5.   turtle.select(1)
  6.   turtle.place()
  7.   turtle.back()
  8.   turtle.select(2)
  9.   turtle.place()
  10.   turtle.up()
  11.   turtle.select(3)
  12.   turtle.place()
  13.   prevLiquid = -1
  14. end
  15.  
  16. function brk()
  17.   turtle.select(3)
  18.   turtle.dig()
  19.   turtle.down()
  20.   turtle.select(2)
  21.   turtle.dig()
  22.   turtle.select(1)
  23.   turtle.forward()
  24.   turtle.dig()
  25. end
  26.  
  27. function move()
  28.   turtle.turnRight()
  29.  
  30.   for i = 1, 10 do
  31.     turtle.forward()
  32.     sleep(2)
  33.   end
  34. end
  35.  
  36. function hasLessLiquid()
  37.   local tank = peripheral.wrap("front")
  38.   local amount = tank.getTankInfo("front")[1]["amount"]
  39.  
  40.   if amount < prevLiquid then
  41.     return true
  42.   end
  43.  
  44.   prevLiquid = amount
  45.   return false
  46. end
  47.  
  48.  
  49. function waitForTankOrMsg()
  50.   while true do
  51.     local id,msg = rednet.receive(5)
  52.     if id ~= nil and msg ~= nil then
  53.       if id == 1 and msg == "break" then
  54.         brk()
  55.       end
  56.     else
  57.       if hasLessLiquid() then
  58.         sendStop()
  59.         break
  60.       end
  61.     end
  62.   end
  63. end
  64.  
  65. function sendStop()
  66.   rednet.send(1,"break")
  67. end
  68.  
  69. while true do
  70.   id,msg = rednet.receive()
  71.  
  72.   if id == 1 then
  73.     if msg == "place" then
  74.       place()
  75.       waitForTankOrMsg()
  76.     elseif msg == "move" then
  77.       move()
  78.     elseif msg == "break" then
  79.       brk()
  80.     end
  81.   end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement