Posted 21 December 2014 - 08:17 AM
Trying to automate my big reactor with manual button inputs to turn on and off the reactor in order to not waste fuel. When i reach the lower end of the spectrum the reactor will not turn on automatically. I have atm edited the code again to see if a fix i thought of works. it takes about 4-5 hours after the auto turnoff to see if the program will work correctly (this is mainly due to my power consumption rate is low). Below is the current code that i am working with. The reactor will automatically turn off correctly but will not turn back on. Due note that the code has to work with the buttons. And if you can't tell this is running on an advance computer.
Edit* So it seems that once i use a button that it begins to act weird. It no longer runs in 1 second intervals like i set up in the code. Only 100% fix i have found is to reboot the whole computer after pressing the button.
Edit* So it seems that once i use a button that it begins to act weird. It no longer runs in 1 second intervals like i set up in the code. Only 100% fix i have found is to reboot the whole computer after pressing the button.
--Created by Almerish
--Single rod no liquid big reactor
while true do
local reactor = peripheral.wrap("BigReactors-Reactor_0")
local energy = reactor.getEnergyStored()
local Active = paintutils.loadImage("button")
local DeActive = paintutils.loadImage("button2")
--printing information and button
print("Connected: ", reactor.getConnected())
print("Stored Energy: ", energy)
print("Reactor Status: ", reactor.getActive())
paintutils.drawImage(Active, 6, 12)
term.setCursorPos(7, 14)
print("Activate")
paintutils.drawImage(DeActive, 38, 12)
term.setCursorPos(38, 14)
print("DeActivate")
local refresh = os.startTimer(1)
local event, button, x, y = os.pullEvent()
--click-able button
if event == "mouse_click" and x >= 6 and x <= 16 and y >= 12 and y <= 17 then
reactor.setActive(true)
elseif event == "mouse_click" and x >= 38 and x <= 48 and y >= 12 and y <= 17 then
reactor.setActive(false)
--auto-update for turning reactor on and off
elseif event == "timer" and button == refresh then
if energy >= 9800000 then
reactor.setActive(false)
elseif energy <= 200000 then
reactor.setActive(true)
end
end
--resetting screen
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
end
Edited on 21 December 2014 - 07:32 AM