Advertisement
machasins

long distance toggle

Aug 5th, 2022 (edited)
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. peripheral.find("modem", rednet.open)
  2. local input = false
  3. print("Reading starting data...")
  4. file = io.input("wirelesssavedata")
  5. if (file ~= nil) then
  6.   state = io.read()
  7.   if (state == "true") then
  8.     redstone.setOutput("right", true)
  9.   else
  10.     redstone.setOutput("right", false)
  11.   end
  12. end
  13. print("Starting loop")
  14. while (true)
  15. do
  16.   if (redstone.getInput("left")) then
  17.     if (input == false) then
  18.       print("Sending ping...")
  19.       rednet.send(tonumber(arg[1]), "ping")
  20.       redstone.setOutput("right", not redstone.getOutput("right"))
  21.       file = io.output("wirelesssavedata")
  22.       if (file ~= nil) then
  23.         io.write(tostring(redstone.getOutput("right")))
  24.       end
  25.     end
  26.     input = true
  27.   else
  28.     input = false
  29.   end
  30.   local id, msg = rednet.receive(nil, 0.1)
  31.   if (id == tonumber(arg[1]) and msg == "ping") then
  32.     print("Received ping...")
  33.     redstone.setOutput("right", not redstone.getOutput("right"))
  34.     file = io.output("wirelesssavedata")
  35.     if (file ~= nil) then
  36.       io.write(tostring(redstone.getOutput("right")))
  37.     end
  38.   end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement