Advertisement
Guest User

startup

a guest
Dec 21st, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1, 1)
  3.  
  4. print("Starting Client")
  5.  
  6. rednet.open("back")
  7. sleep(1)
  8.  
  9. while true do
  10.   term.clear()
  11.   term.setCursorPos(1, 1)
  12.   print("Enter a command")
  13.  
  14.   local input = read()
  15.  
  16.   if input~="" then
  17.     rednet.broadcast("Ping")
  18.     print("Trying connection")
  19.     local id,message,distance = rednet.receive(1)
  20.     print("Received '"..message.."' from id:"..id)
  21.    
  22.     local nextid = -1
  23.    
  24.    
  25.     if message==nil then
  26.       print("No connections found")
  27.       sleep(1)
  28.     else
  29.       local timeout = 0
  30.       while id~=nextid do
  31.         nextid,message,distance = rednet.receive(1)
  32.         if message~=nil then
  33.           print("Message '"..message.."' received from id:"..nextid)
  34.         end
  35.         timeout = timeout+1
  36.         if timeout == 10 then
  37.           print("Connection timeout")
  38.           sleep(2)
  39.           os.reboot()
  40.         end
  41.       end
  42.       print(message)
  43.       sleep(2)
  44.      
  45.     end
  46.   end
  47.  
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement