View difference between Paste ID: F5vCJRPx and 28if8sqa
SHOW: | | - or go back to the newest paste.
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
end
27
28
29
function testMessage()
30
  id, message = rednet.receive()
31
  if message == "t" then
32
    if id == masterID then
33
      outputBool = not outputBool
34
      setRedstone(outputBool)
35
    end
36-
    masterActive = false
36+
37-
    if testMaster(id, message) then
37+
    if message ~= lastmessage then
38
      masterActive = false
39
    end
40
    if testMaster(id, message) and not masterActive then
41
      masterActive = true
42
      lastmessage = message
43
    end
44
  end
45
end
46
47
function setRedstone(state)
48
  print("Setting Redstone to: " .. tostring(state))
49
  redstone.setOutput("back", state)
50
end
51
52
setRedstone(outputBool)
53
54
rednet.open("top")
55
56
while true do
57
  testMessage()
58
end