icdb

[Computercraft] receiver new

Aug 6th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --receiver
  2. currenthost = ""
  3.  
  4. local function openRednet()
  5.   for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
  6.     if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  7.       rednet.open(side)
  8.       return side
  9.     end
  10.   end
  11.   print("no modem present")
  12. end
  13.  
  14. side = openRednet()
  15. if side == nil then
  16. print("no modem found")
  17. else
  18.   while true do
  19.     event, id, message, distance = os.pullEvent("rednet_message")
  20.     if message == "newhost" then
  21.       rednet.send(id,"pairing")
  22.     end
  23.     if string.sub(message,1,string.len("connected"))=="connected" then
  24.       currenthost = string.sub(message,10)
  25.       print("New host: " .. currenthost)
  26.     end
  27.    
  28.   end
  29.    
  30.    
  31.     print(message)
  32.     shell.switchTab(shell.openTab(message))
  33.     shell.exit()
  34. end
Add Comment
Please, Sign In to add comment