Advertisement
Shurhaian

ComputerCraft "every Nth" egg distributor

Mar 12th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. local deplSide = "right" -- Transposer leading to the deployer
  2. local chstSide = "left" -- Transposer leading to catch chest
  3. local holdSide = "top" -- Input to shut off the deployer and send all output to catch chest
  4. local offSide = "back" -- Input to halt activity entirely
  5. local deployN = 4 -- Send N eggs to the deployer for every one that gets saved
  6. local countN = 1 -- Start the counter at 1
  7. local version = "1.2"
  8.  
  9. local function redPulse( side )
  10.     redstone.setOutput( side, true )
  11.     sleep(0.1)
  12.     redstone.setOutput( side, false )
  13. end
  14.  
  15.  
  16. local function main()
  17.     print("SkunkWorks Logistics")
  18.     print("Egg processing routine v"..version)
  19.     print("If routine has been aborted, run 'eggtimer' to restart it")
  20.     while true do
  21.         if rs.getInput( offSide ) then
  22.             os.pullEvent("redstone") -- Wait for a redstone input to change, otherwise stop looping
  23.         else
  24.             if rs.getInput( holdSide ) then
  25.                 redPulse( chstSide )
  26.             else
  27.                 countN = countN + 1
  28.                 if countN >= deployN then
  29.                     redPulse( chstSide)
  30.                     countN = 1 -- Reset the counter
  31.                 else
  32.                     redPulse(deplSide)
  33.                 end
  34.             end
  35.         sleep(1)
  36.         end
  37.     end
  38. end
  39.  
  40.  
  41. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement