Kulgan_Starkk

rednetGet

Mar 27th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. slaveName = "5"
  2. masterID = 0
  3. outputBool = false
  4. masterActive = false
  5.  
  6. function testMaster(pID, pMessage)
  7.   pID = pID or -1
  8.   if pID == -1 then
  9.     while true do
  10.       id, message = rednet.receive()
  11.       if message == "KKRNBTNMaster" then
  12.         rednet.send(id, slaveName)
  13.         masterID = id
  14.         print("Discovered Master with ID: " .. id)
  15.         return true
  16.       end  
  17.     end
  18.   else
  19.     if message == "KKRNBTNMaster" then
  20.       rednet.send(pID, slaveName)
  21.       masterID = pID
  22.       print("Discovered Master with ID: " .. pID)
  23.       return true
  24.     end  
  25. end
  26.  
  27.  
  28. function testMessage()
  29.   id, message = rednet.receive()
  30.   if message == "t" then
  31.     if id == masterID then
  32.       outputBool = not outputBool
  33.       setRedstone(outputBool)
  34.     end
  35.   else
  36.     masterActive = false
  37.     if testMaster(id, message) then
  38.       masterActive = true
  39.     end
  40.   end
  41. end
  42.  
  43. function setRedstone(state)
  44.   print("Setting Redstone to: " .. tostring(state))
  45.   redstone.setOutput("back", state)
  46. end
  47.  
  48. setRedstone(outputBool)
  49.  
  50. rednet.open("top")
  51.  
  52. while true do
  53.   testMessage()
  54. end
Advertisement
Add Comment
Please, Sign In to add comment