SHOW:
|
|
- or go back to the newest paste.
1 | rednet.open("right") | |
2 | ||
3 | local Archi,BW,Gau = colors.purple, colors.orange, colors.yellow | |
4 | local ResetColor = colors.white | |
5 | local ID | |
6 | - | event, ID,message, distance = os.pullEvent("rednet_message") |
6 | + | local ignoreReset = 0 |
7 | - | if ( string.sub(message,1,4) == "rail" ) then |
7 | + | |
8 | - | local value = tonumber(string.sub(message,5)) |
8 | + | function sendNewCode(myColors) |
9 | - | local newColor = 0 |
9 | + | |
10 | - | if ( bit.band(value, 1) ~= 0 ) then newColor = colors.combine(newColor,Archi) end |
10 | + | |
11 | - | if ( bit.band(value, 2) ~= 0 ) then newColor = colors.combine(newColor,BW) end |
11 | + | |
12 | - | if ( bit.band(value, 4) ~= 0 ) then newColor = colors.combine(newColor,Gau) end |
12 | + | |
13 | - | rs.setBundledOutput("back",newColor) |
13 | + | if ( ID ~= nil ) then |
14 | rednet.send(ID,"rail" .. value) | |
15 | - | if ( message == "ping" ) then |
15 | + | else |
16 | - | os.sleep(1) |
16 | + | rednet.broadcast("rail" .. value) |
17 | - | local myColors = rs.getBundledOutput("back") |
17 | + | end |
18 | end | |
19 | ||
20 | function resetNetwork() | |
21 | ignoreReset = 1 | |
22 | - | rednet.send(ID,"rail" .. value) |
22 | + | rs.setBundledOutput("back",ResetColor) |
23 | os.sleep(0.5) | |
24 | rs.setBundledOutput("back",0) | |
25 | end | |
26 | ||
27 | while true do | |
28 | ||
29 | event, ID,message, distance = os.pullEvent() | |
30 | if ( event == "rednet_message" ) then | |
31 | ||
32 | if ( string.sub(message,1,4) == "rail" ) then | |
33 | local value = tonumber(string.sub(message,5)) | |
34 | local newColor = 0 | |
35 | if ( bit.band(value, 1) ~= 0 ) then newColor = colors.combine(newColor,Archi) end | |
36 | if ( bit.band(value, 2) ~= 0 ) then newColor = colors.combine(newColor,BW) end | |
37 | if ( bit.band(value, 4) ~= 0 ) then newColor = colors.combine(newColor,Gau) end | |
38 | resetNetwork() | |
39 | rs.setBundledOutput("back",newColor) | |
40 | end | |
41 | if ( message == "ping" ) then | |
42 | os.sleep(1) | |
43 | local myColors = rs.getBundledInput("front") | |
44 | sendNewCode(myColors) | |
45 | end | |
46 | end | |
47 | if ( event == "redstone" and colors.test(rs.getBundledInput("front"),colors.white) ) then | |
48 | if ( ignoreReset == 0 ) then | |
49 | ||
50 | rs.setBundledOutput("back",0) | |
51 | os.sleep(5) | |
52 | local myColors = rs.getBundledInput("front") | |
53 | sendNewCode(myColors) | |
54 | else | |
55 | ignoreReset = 0 | |
56 | end | |
57 | end | |
58 | end |