Volaik

s3

Nov 12th, 2021 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. CLIENT_PORT = 0
  2. io.write("Set a server port: ")
  3. SERVER_PORT = tonumber(io.read())
  4. print("Server port has been set to: "..SERVER_PORT)
  5.  
  6. local modem = peripheral.find("modem")
  7. modem.open(SERVER_PORT)
  8.  
  9. if CLIENT_PORT == 0 then
  10.     print("I am not broadcasting to anyone")
  11. end
  12.  
  13.  
  14. function pingLoc()
  15.     io.write("Select robot to ping: ")
  16.     local num1 = tonumber(io.read())
  17.     modem.transmit(num1, SERVER_PORT, "pingLoc")
  18.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  19.     print(message)
  20. end
  21.  
  22. while true do
  23.  
  24.     event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  25.     if message == "connectMessage" then
  26.         print("Connection detected from "..replyChannel)
  27.         modem.transmit(replyChannel, SERVER_PORT, "connectSuccess")
  28.     end
  29.  
  30.     while true do
  31.         local command = io.read()
  32.  
  33.         if command == "Loc" then
  34.             pingLoc()
  35.         end
  36.     end
  37.    
  38. end
Add Comment
Please, Sign In to add comment