SHOW:
|
|
- or go back to the newest paste.
| 1 | slaveName = "5" | |
| 2 | masterID = 0 | |
| 3 | outputBool = false | |
| 4 | masterActive = false | |
| 5 | - | function testMaster(pID = -1, pMessage) |
| 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 | - | rednet.send(pID, slaveName) |
| 17 | + | |
| 18 | - | masterID = pID |
| 18 | + | |
| 19 | - | print("Discovered Master with ID: " .. pID)
|
| 19 | + | if message == "KKRNBTNMaster" then |
| 20 | - | return true |
| 20 | + | rednet.send(pID, slaveName) |
| 21 | masterID = pID | |
| 22 | print("Discovered Master with ID: " .. pID)
| |
| 23 | return true | |
| 24 | end | |
| 25 | end | |
| 26 | ||
| 27 | - | if id == masterID then |
| 27 | + | |
| 28 | - | if message == "t" then |
| 28 | + | |
| 29 | id, message = rednet.receive() | |
| 30 | if message == "t" then | |
| 31 | - | else |
| 31 | + | if id == masterID then |
| 32 | - | testMaster(id, message) |
| 32 | + | |
| 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 |