Advertisement
Guest User

cellfarm.lua

a guest
Dec 7th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. local rs = peripheral.find("redstoneIntegrator")
  2. if not rs then error("No redstone integrator") end
  3. local dandelifeon = "south"
  4. local destructor = "north"
  5. local constructor = "up"
  6. local lever = "west"
  7. local cancelKey = keys.c
  8.  
  9. local function pulse(direction, duration)
  10.     if not duration then duration = 1 end
  11.     rs.setOutput(direction, true)
  12.     sleep(duration)
  13.     rs.setOutput(direction, false)
  14. end
  15.  
  16. local function initOutput(direction)
  17.     rs.setOutput(direction, false)
  18. end
  19.  
  20. initOutput(dandelifeon)
  21. initOutput(destructor)
  22. initOutput(constructor)
  23.  
  24. local function main()
  25.     print("Cellular Block Farm")
  26.     while true do
  27.         if rs.getInput(lever) then
  28.             sleep(1)
  29.         else
  30.             pulse(destructor)
  31.             pulse(constructor)
  32.             pulse(dandelifeon, 2)
  33.         end
  34.     end
  35. end
  36.  
  37. local function canceller()
  38.     print("Program is running now, press", keys.getName(cancelKey), "to cancel")
  39.     while true do
  40.         local event, key = os.pullEvent("key")
  41.         if key == cancelKey then
  42.             print("Okay, goodbye...")
  43.             return
  44.         end
  45.     end
  46. end
  47.  
  48. parallel.waitForAny(main, canceller)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement