Kulgan_Starkk

Untitled

Mar 27th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. slaveName = "5" -- number of button to assign to
  2. masterID = 0
  3. outputBool = false -- default (off) state of redstone power for spawner, false means off
  4. masterActive = false
  5. lastmessage = "foo" -- meaningless message
  6.  
  7. function testMaster(pID, pMessage)
  8.   if message == "KKRNBTNMaster" then
  9.     rednet.send(pID, slaveName)
  10.     masterID = pID
  11.     print("Discovered Master with ID: " .. pID)
  12.     return true
  13.   end  
  14. end
  15.  
  16.  
  17. function testMessage()
  18.   id, message = rednet.receive()
  19.   if message == "t" then
  20.     if id == masterID then
  21.       outputBool = not outputBool
  22.       setRedstone(outputBool)
  23.       lastmessage = message
  24.     end
  25.   else
  26.     if message ~= lastmessage then
  27.       masterActive = false
  28.     end
  29.     if not masterActive then
  30.       testMaster(id, message)
  31.       masterActive = true
  32.       lastmessage = 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