Advertisement
melzneni

sys2_service_doorTerminal

Feb 10th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. --sys2_service_doorTerminal
  2.  
  3. os.loadAPI("sys/syslib")
  4.  
  5. --syslib end
  6.  
  7. local msgBefore = ""
  8. while true do
  9. shell.run("clear")
  10. if msgBefore ~= "" then print(msgBefore) end
  11. io.write("password:")
  12. local pwd = read("*")
  13. rednet.broadcast("@doorLock:password," .. pwd)
  14. local opened = false
  15. local closed = false
  16. local failed = false
  17. msgBefore = ""
  18.  
  19. while (not opened or not closed) and not failed do
  20. local id, msg = syslib.receiveRednet()
  21. local tag, pts = syslib.getMsgData(msg)
  22.  
  23. if tag == "@doorTerminal" then
  24. if pts[1] == "open" then
  25. opened = true
  26. print("door is open")
  27. elseif pts[1] == "closed" then
  28. if not opened then
  29. failed = true
  30. else
  31. closed = true
  32. end
  33. elseif pts[1] == "fail" then
  34. failed = true
  35. msgBefore = "wrong password"
  36. else print("unknown message: ", msg)
  37. end
  38. end
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement