Advertisement
Fugiman

DigMaster

Apr 2nd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. function count(table)
  2.     local num = 0;
  3.     for _ in pairs(table) do num = num + 1 end
  4.     return num
  5. end
  6.  
  7. function call(port, command)
  8.     local begun = false
  9.     local pending = {}
  10.     local modem = peripheral.wrap("left")
  11.     modem.open(port)
  12.     modem.transmit(port, port, command)
  13.     print("Start message sent...")
  14.     repeat
  15.         local a, b, c, sender, message, d = os.pullEvent("modem_message")
  16.         if message == "start" then
  17.             pending[sender] = true
  18.             print("#"..sender.." starting ("..count(pending).." running)")
  19.             begun = true
  20.         end
  21.         if message == "finish" then
  22.             pending[sender] = nil
  23.             print("#"..sender.." finished ("..count(pending).." running)")
  24.         end
  25.     until count(pending) == 0 and begun
  26.     print("...all done!")
  27. end
  28.  
  29. function pulse(side)
  30.     redstone.setOutput(side, true)
  31.     sleep(0.4)
  32.     redstone.setOutput(side, false)
  33.     sleep(0.4)
  34. end
  35.  
  36. function move()
  37.     pulse("back")
  38.     sleep(0.2)
  39.     pulse("right")
  40.     sleep(0.2)
  41. end
  42.  
  43. function cycle()
  44.     move()
  45.     call(8080, "cycle")
  46.     sleep(4)
  47. end
  48.  
  49. function run()
  50.     while true do
  51.         if redstone.getInput("top") == true then
  52.             cycle()
  53.         end
  54.         sleep(2)
  55.     end
  56. end
  57.  
  58. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement