Kulgan_Starkk

rednetGet

Mar 27th, 2014
163
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.  
  5. function testMaster(pID = -1, pMessage)
  6.   if pID == -1 then
  7.     while true do
  8.       id, message = rednet.receive()
  9.       if message == "KKRNBTNMaster" then
  10.         rednet.send(id, slaveName)
  11.         masterID = id
  12.         print("Discovered Master with ID: " .. id)
  13.         return true
  14.       end  
  15.     end
  16.   else
  17.     rednet.send(pID, slaveName)
  18.     masterID = pID
  19.     print("Discovered Master with ID: " .. pID)
  20.     return true
  21.   end
  22. end
  23.  
  24.  
  25. function testMessage()
  26.   id, message = rednet.receive()
  27.   if id == masterID then
  28.     if message == "t" then
  29.       outputBool = not outputBool
  30.       setRedstone(outputBool)
  31.     else
  32.       testMaster(id, message)
  33.     end
  34.   end
  35. end
  36.  
  37. function setRedstone(state)
  38.   print("Setting Redstone to: " .. tostring(state))
  39.   redstone.setOutput("back", state)
  40. end
  41.  
  42. setRedstone(outputBool)
  43.  
  44. rednet.open("top")
  45.  
  46. while true do
  47.   testMessage()
  48. end
Advertisement
Add Comment
Please, Sign In to add comment