Guest User

API

a guest
Sep 2nd, 2013
15
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local oldRednet = rednet
  2. local oldSide = false
  3.  
  4.  
  5. -- shorter functions
  6. local net = rednet
  7. local brod = net.broadcast
  8. local pull = os.pullEvent
  9.  
  10. function send(id, msg)
  11.     net.send(id, msg)
  12. end
  13.  
  14. function setMaster(ID)
  15.     local save = fs.open(".master", "w")
  16.     save.writeLine(tonumber(ID))
  17.     save.close()
  18. end
  19.  
  20. function getMaster()
  21.     local save = fs.open(".master", "r")
  22.     local cRead = save.readLine()
  23.     save.close()
  24.     return tonumber(cRead)
  25. end
  26.  
  27. function setGlobalMessage(msg)
  28.     local save = fs.open(".global", "w")
  29.     save.writeLine(msg)
  30.     save.close()
  31. end
  32.  
  33. function getGlobalMessage()
  34.     local save = fs.open(".global", "r")
  35.     local cRead = save.readLine()
  36.     save.close()
  37.     return cRead
  38. end
  39.  
  40. function open(side)
  41.     oldSide = side
  42.     rednet.open(side)
  43. end
  44.  
  45. function close()
  46.     rednet.close(oldSide)
  47. end
  48.    
  49. function ping()
  50.     setGlobalMessage(" ")
  51.     brod("ping")
  52.     local id, msg = rednet.receive(2)
  53.     if msg == "pong" then
  54.         setMaster(id)
  55.         setGlobalMessage("Connected")
  56.     end
  57.     -- id, msg, dist = rednet.receive(2)
  58.     -- print(msg)
  59.     -- if msg == "pong" then
  60.     --  setMaster(id)
  61.     --  setGlobalMessage("success")
  62.     -- end
  63.     -- if not id then
  64.     --  term.setTextColor(colors.red)
  65.     --  print("Timeout")
  66.     --  term.setTextColor(colors.white)
  67.     -- end 
  68. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×