SHOW:
|
|
- or go back to the newest paste.
1 | - | local bio = peripheral.wrap("back") |
1 | + | -- Biowatch Program |
2 | - | local modem = peripheral.wrap("bottom") |
2 | + | -- Watches 2 Bioreactors and turns them on/off depending on how many items are in the reactor |
3 | - | local machine = "tile_mfr_machine_bioreactor_name_0" |
3 | + | -- The first reactor will only try to keep one stack of each type of item in its buffer, it will push all |
4 | -- duplicate stacks into the second reactor. | |
5 | -- The first reactor will only turn on when a certain number of items are being processed (default 8) | |
6 | ||
7 | -- The Second reactor will only turn on if there are 8 (defatult) or more items being processed, or if there are | |
8 | -- 6 or more item stacks in the inventory buffer | |
9 | ||
10 | ||
11 | -- In the way it is configured now, the first reactor is behind the computer, | |
12 | -- The second reactor is directly to the north of the first reactor, and is connected to | |
13 | -- the computer via a modem cable. The modem is on the bottom face of the computer | |
14 | -- Connected to the top of the computer is a rednet cable which connects to the two reactors | |
15 | -- The first reactor's connection is colored orange, the second is magenta | |
16 | ||
17 | - | bio.pushItem("north",slot) |
17 | + | -- Note: in order to connect a modem to the second reactor, a Peripheral Proxy is required |
18 | ||
19 | ||
20 | ||
21 | local bio = peripheral.wrap("back") -- Location of first reactor | |
22 | local modem = peripheral.wrap("bottom") -- Location of modem for second reactor | |
23 | local machine = "tile_mfr_machine_bioreactor_name_0" -- Network name of second reactor (this is the default) | |
24 | local CableSide = "top" -- location of rednet cable | |
25 | ||
26 | local pushDirection = "north" -- Location of the second reactor relative to the first | |
27 | ||
28 | local firstReactorColor = colors.orange -- rednet cable color for first reactor | |
29 | local secondReactorColor = colors.magenta -- rednet cable color for first reactor | |
30 | ||
31 | local FirstReactorVariety = 8 -- number of items required in first reactor to turn on | |
32 | local SecondReactorVariety = 8 -- number of items required in second reactor to turn on | |
33 | ||
34 | ||
35 | - | end |
35 | + | |
36 | function getSecondStack(stack) | |
37 | return modem.callRemote(machine,"getStackInSlot",stack) | |
38 | end | |
39 | ||
40 | function isIn(var,tab) | |
41 | for i,v in ipairs(tab) do | |
42 | - | -- print("wee") |
42 | + | |
43 | end | |
44 | return false | |
45 | end | |
46 | ||
47 | function PushItem(slot) | |
48 | bio.pushItem(pushDirection,slot) | |
49 | end | |
50 | ||
51 | ||
52 | -- Checks if it should turn on the second reactor | |
53 | function checkSecond() | |
54 | local count = 0 | |
55 | ||
56 | for i = 1,9 do | |
57 | if ( getSecondStack(i) ~= nil ) then count = count + 1 end | |
58 | end | |
59 | if ( count >= 6 ) then return false end | |
60 | count = 0 | |
61 | - | local first = true |
61 | + | |
62 | for i=10,18 do | |
63 | if ( getSecondStack(i) ~= nil ) then count = count + 1 end | |
64 | - | if ( numOfTypes >= 8 ) then |
64 | + | |
65 | if ( count >= 8 ) then return false end | |
66 | - | --rs.setAnalogOutput("right",true) |
66 | + | |
67 | return true | |
68 | end | |
69 | - | --rs.setOutput("right",false) |
69 | + | |
70 | ||
71 | ||
72 | - | if ( first ) then color = color + colors.orange end |
72 | + | -- Main Loop |
73 | - | if ( second ) then color = color + colors.magenta end |
73 | + | |
74 | - | rs.setBundledOutput("top",color) |
74 | + | |
75 | local idList = {} | |
76 | local numOfTypes = 0 | |
77 | ||
78 | -- Check the inventory of the first reactor, push duplicate stacks to the second reactor. | |
79 | for i=1,9 do | |
80 | local item = bio.getStackInSlot(i) | |
81 | if ( item ~= nil ) then | |
82 | local code = item.id .. "." .. item.dmg | |
83 | if ( isIn(code,idList) ) then | |
84 | -- print("Pushing " .. i .. " " .. item.id) | |
85 | PushItem(i) | |
86 | else | |
87 | -- print("Adding " .. i .. " ".. item.id) | |
88 | table.insert(idList,code) | |
89 | ||
90 | end | |
91 | end | |
92 | end | |
93 | ||
94 | -- Count number of types being processed | |
95 | for i=10,18 do | |
96 | local item = bio.getStackInSlot(i) | |
97 | if ( item ~= nil ) then numOfTypes = numOfTypes + 1 end | |
98 | end | |
99 | ||
100 | -- Now determine if reactor should be on or off | |
101 | local first = true | |
102 | local second = checkSecond() | |
103 | if ( numOfTypes >= FirstReactorVariety ) then | |
104 | first = false | |
105 | else | |
106 | first = true | |
107 | end | |
108 | ||
109 | -- set the color outputs for the rednet cable | |
110 | local color = 0 | |
111 | if ( first ) then color = color + firstReactorColor end | |
112 | if ( second ) then color = color + secondReactorColor end | |
113 | rs.setBundledOutput(CableSide,color) | |
114 | ||
115 | ||
116 | os.sleep(10) | |
117 | end |