Advertisement
Guest User

SSS

a guest
Dec 9th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. rednet.open("top")
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. local logged = false
  5. local password = "master1"
  6.  
  7. while logged ~= true do
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10.     print("===========================\n")
  11.     print("Password: ")
  12.     local input = read("*")
  13.     if input == password then
  14.         print("\nAccess granted")
  15.         sleep(5)
  16.         logged = true;
  17.     end
  18. end
  19.  
  20. while logged == true do
  21.     local status = "neither"
  22.     print("\nTerminal user 1.0\n")
  23.     print("Set the SlaveID: ")
  24.     local slaveID = read()
  25.     local orderToken = string.format("%s%s" , "order" , slaveID)
  26.     local callToken = string.format("%s%s" , "callBack" , slaveID)
  27.  
  28.     print("\nWaiting for master...")
  29.  
  30.     if status ~= "on" then
  31.  
  32.         local senderId, message, protocol = rednet.receive("master")
  33.  
  34.         if message == "Connected" then
  35.             status = "WakingUp"
  36.             rednet.broadcast(callToken,orderToken)
  37.             senderId, message, protocol = rednet.receive(orderToken,2)
  38.             print("\nWoken up, waiting for call token...") 
  39.         end
  40.  
  41.         if message == callToken then
  42.             status = "on"
  43.             rednet.broadcast("Ready",callToken)
  44.             senderId, message, protocol = rednet.receive(orderToken,2)
  45.             print("\nSuccesfully synchronized !")
  46.         end
  47.  
  48.     end
  49.  
  50.     if status == "on" then
  51.         rs.setOutput("front",true)
  52.         if rs.getInput("right") == true then
  53.             rednet.broadcast("Overheated\n",callToken)
  54.         end
  55.         if rs.getInput("left") == true then
  56.             rednet.broadcast("Ready to work\n",callToken)
  57.         end
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement