legg0028

secret_door_receive

Aug 1st, 2021 (edited)
1,060
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local modem = peripheral.wrap("right")
  2. modem.open(00004)
  3.  
  4. redstone.setOutput("front",true)
  5. redstone.setOutput("top",false)
  6.  
  7. if fs.exists("save_data.lua") then
  8.     local h = fs.open("save_data.lua", "r")
  9.     local data = h.readAll()
  10.     h.close()
  11.     compNum = data
  12.     compMsg = "s"..compNum
  13. end
  14.  
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. print("Waiting on message")
  18.  
  19. while true do
  20.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  21.  
  22.     term.clear()
  23.     term.setCursorPos(1,1)
  24.     print("Message received: "..message)
  25.     print("Channel: "..senderChannel)
  26.  
  27.     if senderChannel == 4 then
  28.         if message == compMsg then
  29.             redstone.setOutput("front",true)
  30.             redstone.setOutput("top",true)
  31.             sleep(0.1)
  32.             redstone.setOutput("front",false)
  33.         elseif message == "serror" then
  34.             for x = 1,4 do
  35.                 redstone.setOutput("front",true)
  36.                 redstone.setOutput("top",true)
  37.                 sleep(0.1)
  38.                 redstone.setOutput("front",false)
  39.                 redstone.setOutput("top",false)
  40.                 sleep(0.1)
  41.             end
  42.         end
  43.     end
  44.     sleep(0.1)
  45. end
RAW Paste Data