Advertisement
Guest User

Untitled

a guest
Aug 10th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. local controller = 0
  2.  
  3. local name = ""
  4. local dType = ""
  5. local passcode = ""
  6.  
  7. function load(n,t,p,s)
  8. name = n
  9. dType = t
  10. passcode = p
  11.  
  12. if s ~= nil then
  13. controller = s
  14. end
  15. end
  16.  
  17. function listen(commandArray)
  18. while true do
  19. commands = {}
  20. commands = commandArray
  21.  
  22. e,p1,p2,p3,p4 = os.pullEvent()
  23.  
  24. if e == "modem_message" and p3 == controller then
  25. id = p3
  26. msgPackage = p4
  27.  
  28. msg = msgPackage["message"]
  29.  
  30. msgParts = textutils.unserialize(msg)
  31.  
  32. if msgParts[1] ~= nil and id == controller then
  33.  
  34. commandInList = false
  35. for i,v in pairs(commands) do
  36. if i == msgParts[1] then
  37. commandInList = true
  38. end
  39. end
  40.  
  41. if commandInList then
  42. commands[msgParts[1]](msgParts[2])
  43. end
  44. end
  45. end
  46. end
  47. end
  48.  
  49. function attatch(commandList)
  50. commands = {}
  51. commands = commandList
  52.  
  53. commandNames = {}
  54.  
  55. for i,v in pairs(commands) do
  56. table.insert(commandNames, i)
  57. end
  58.  
  59. message = {"createDevice", passcode, name, dType, commandNames}
  60. message = textutils.serialize(message)
  61.  
  62. rednet.send(controller, message)
  63. end
  64.  
  65. function detatch()
  66. message = {"detatchDevice", passcode, name}
  67.  
  68. message = textutils.serialize(message)
  69.  
  70. rednet.send(controller,message)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement