SHOW:
|
|
- or go back to the newest paste.
| 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 |
| 5 | + | |
| 6 | function testMaster(pID, pMessage) | |
| 7 | if message == "KKRNBTNMaster" then | |
| 8 | rednet.send(pID, slaveName) | |
| 9 | masterID = pID | |
| 10 | print("Discovered Master with ID: " .. pID)
| |
| 11 | masterActive = true | |
| 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 |
| 23 | + | |
| 24 | else | |
| 25 | if message == "KKRNBTNReload" then | |
| 26 | - | if message ~= lastmessage then |
| 26 | + | |
| 27 | end | |
| 28 | if not masterActive then | |
| 29 | testMaster(id, message) | |
| 30 | end | |
| 31 | - | masterActive = true |
| 31 | + | |
| 32 | - | lastmessage = message |
| 32 | + | |
| 33 | ||
| 34 | function setRedstone(state) | |
| 35 | print("Setting Redstone to: " .. tostring(state))
| |
| 36 | redstone.setOutput("back", state)
| |
| 37 | end | |
| 38 | ||
| 39 | setRedstone(outputBool) | |
| 40 | ||
| 41 | rednet.open("top")
| |
| 42 | ||
| 43 | while true do | |
| 44 | testMessage() | |
| 45 | end |