This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MastInvincible's profile picture

Reactor Flush program not working.

Started by MastInvincible, 11 July 2015 - 09:58 PM
MastInvincible #1
Posted 11 July 2015 - 11:58 PM
Hello. I've started making a nuclear reactor control program on a computer. I've set the reactor up and started working on the computer, however, the flush program doesn't work. Can anyone help? The second part works but the pulse i've made doesn't. In some cases it pulses once or twice and then just stops. Here's the code:


local function addcol(colour, side)
rs.setBundledOutput(side, colours.combine(rs.getBundledOutput(side),col))
end
local function remcol(colour, side)
rs.setBundledOutput(side, colours.subtract(rs.getBundledOutput(side),col))

term.clear()
print("Flushing...")
while rs.testBundledInput("back", colours.red) do
rs.setBundledOutput("back", colours.blue)
sleep(1)
remcol(colours.blue, 'back')
end
end
while rs.testBundledInput("back", colours.red) do
rs.setBundledOutput("back", colours.magenta)
sleep(80)
os.reboot()
end
Bomb Bloke #2
Posted 12 July 2015 - 12:58 AM
You seem to have a miss-placed "end" statement there - wouldn't you want to place one immediately above that term.clear() call, finishing off the remcol() function declaration (removing one of the two "end"s you've got under that first "while" loop)?

With the "end" where it is, that first "while" loop won't ever be processed. But if you moved it, then the loop would turn blue on if red were on, then a second later turn it off, then without delay turn it on again, and so on. If you wanted a "pulse" then you'd want to use two sleeps in there - one to determine how long the signal should be enabled, and one to determine how long it should be disabled.
MastInvincible #3
Posted 12 July 2015 - 10:23 AM
Hello. Back again. I tried the changes you suggested and now the pulse is stuck on. I put an end after the remcol function and removed the other one. I added the sleep after remcol blue and I needed to swap the 2 colours around because I made a mistake but it should still work right? It is running the code because it clears the screen and writes flushing. Help?

Edit: I found a temporary f ix. It turns out the remcol function doesn't work so I changed it to set bundled outputs to 0 but it's not ideal. If anyone has a way to only turn off one output please tell me. I will keep looking into this. Thanks!
Edited on 12 July 2015 - 10:27 AM
flaghacker #4
Posted 12 July 2015 - 01:03 PM
Disabling the red signal on the right side would look something like this:


rs.setBundledOutput ("right", colors.subtract (rs.getBundledInput ("right"), colors.red))
Edited on 12 July 2015 - 11:04 AM
MastInvincible #5
Posted 12 July 2015 - 02:40 PM
Disabling the red signal on the right side would look something like this:


rs.setBundledOutput ("right", colors.subtract (rs.getBundledInput ("right"), colors.red))

Ok. Thanks.