Advertisement
RabaGhast

RedstoneGateController

Oct 20th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.64 KB | None | 0 0
  1. sleepTime = 0.1
  2. timeLeft = 3
  3.  
  4.  
  5. function openGate()
  6.   print("openGate started")
  7.   timeLeft = 3
  8.   rs.setOutput("top", true)
  9.   oldTime = timeLeft
  10.   while timeLeft > 0 do
  11.     if timeLeft ~= oldTime then    --if a new thread runs openGate, stop this thread
  12.       return
  13.     end
  14.     sleep(sleepTime)
  15.     timeLeft, oldTime = timeLeft - sleepTime
  16.   end
  17.   rs.setOutput("top", false)
  18. end
  19.  
  20. while true do
  21.   shell.run("clear")
  22.   if rs.getInput("bottom") then
  23.     print("redstone ON")
  24.     print("creating coroutine")
  25.     co = coroutine.create(openGate)
  26.     coroutine.resume(co)
  27.   else
  28.     print("redstone OFF")
  29.   end
  30.   os.pullEvent("redstone")
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement