Advertisement
Guest User

lost.lua

a guest
Apr 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. local component = require("component")
  2. local rs = component.redstone
  3. local event = require("event")
  4.  
  5. local code = { 4, 8, 15, 16, 23, 42 }
  6.  
  7. -- one minecraft minute is one second in real time (whatever reality is...)
  8.  
  9. local time = 108
  10.  
  11. local detonationSide=require("sides").east
  12.  
  13. local validCode
  14.  
  15. function checkCode(code)
  16.   return code == tonumber(io.read())
  17. end
  18.  
  19. rs.setOutput(detonationSide, 0)
  20.  
  21. function stop(side)
  22.   rs.setOutput(side, 15)
  23.   require("term").clear()
  24.   print("mind booooom")
  25.   os.exit()
  26. end
  27.  
  28.  
  29. local term = require("term")
  30.  
  31. local codeCompleted
  32. repeat
  33.   codeCompleted = false    
  34.   event.timer(time/2, function() if not codeCompleted then stop() end end)
  35.   term.clear()
  36.  
  37.   print("enter code")
  38.  
  39.   for i=1,#code do
  40.     validCode = checkCode(code[i])
  41.     if not validCode then
  42.       stop(detonationSide)
  43.     end
  44.   end
  45.   codeCompleted = true
  46.  
  47.   term.clear()
  48.   print("please wait...")
  49.   os.sleep(time)
  50. until not validCode
  51.  
  52. stop(detonationSide)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement