Posted 23 April 2014 - 10:41 PM
Hello everyone,
Im using computercraft to control my nuclear reactor.
Everything works fine except one thing.
Turning off the reactor and rebooting the computer doesnt work.
at line 30 I added this code:
But it seems not working and im struggling with this for several days now.
Maybe somebody knows the answer.
Full code below:
Im using computercraft to control my nuclear reactor.
Everything works fine except one thing.
Turning off the reactor and rebooting the computer doesnt work.
at line 30 I added this code:
elseif green == "true" then
os.reboot()
But it seems not working and im struggling with this for several days now.
Maybe somebody knows the answer.
Full code below:
mon = peripheral.wrap("left")
rednet.open("top")
mon = peripheral.wrap("left")
mon.setBackgroundColor(colors.black)
green = rs.testBundledInput("back", colors.green) -- SHUTDOWN CONSOLE
temp = 1
reactor = "Querying"
maxHeat = 1
output = "Querying"
timeLeft = "Querying"
tempPercent = "Querying"
adjustTemp = 5000
x,y = mon.getSize()
rednet.broadcast("ping")
reactorCom = 358 -- reactor computer ID
maxStorageL = "1"
energyL = "1"
nir = 313 -- Nuclear information reader ID
function display()
mon.setTextColor(colours.black)
if reactor == "false" then
mon.setBackgroundColor(colors.red)
rectr = "OFF"
elseif reactor == "true" then
mon.setBackgroundColor(colors.lime)
rectr = "ON"
elseif green == "true" then
os.reboot()
else
rectr = "QRY"
mon.setBackgroundColor(colors.orange)
end
p = 1
for i = 1,3 do
mon.setCursorPos(x-5, p)
mon.write(" ")
p = p + 1
end
p = 0
mon.setCursorPos(x-4, 2)
mon.write(rectr)
mon.setBackgroundColor(colours.black)
mon.setTextColor(colors.white)
mon.setCursorPos(x/3+1, y-2)
mon.write("Reactor Temp: "..tempPercent.."%")
mon.setCursorPos(1, y-1)
mon.setBackgroundColor(colours.black)
mon.setTextColor(colors.green)
mon.write("0%")
mon.setCursorPos(x/2, y-1)
mon.setBackgroundColor(colours.black)
mon.setTextColor(colors.orange)
mon.write("50%")
mon.setCursorPos(x-3, y-1)
mon.setBackgroundColor(colours.black)
mon.setTextColor(colors.red)
mon.write("100%")
if tempPercent == "Querying" --[[or tempPercent == 0 ]] then
mon.setCursorPos(1, y)
mon.write("Temprature Unknown... Querying")
elseif tempPercent/2 < 1 then
mon.setCursorPos(1, y)
mon.setBackgroundColor(colors.lime)
mon.write(" ")
mon.setBackgroundColor(colors.black)
else
for i = 1, tempPercent, 2 do
p = p + 1
mon.setCursorPos(p,y)
if p < x/4 then
mon.setBackgroundColor(colors.lime)
mon.write(" ")
mon.setBackgroundColor(colors.black)
elseif p < x/2 then
mon.setBackgroundColor(colors.green)
mon.write(" ")
mon.setBackgroundColor(colors.black)
elseif p < x/4*3 then
mon.setBackgroundColor(colors.orange)
mon.write(" ")
mon.setBackgroundColor(colors.black)
elseif p <= x then
mon.setBackgroundColor(colors.red)
mon.write(" ")
mon.setBackgroundColor(colors.black)
end
end
p = 0
end
end
local result
result = fs.exists("shutTemp")
if result == true then
file = io.open("shutTemp", "r")
shutTemp = file:read()
file:close()
elseif result == false then
shutTemp = 1000
end
local result
result = fs.exists("rctrStatus")
if result == true then
file = io.open("rctrStatus", "r")
reactor = file:read()
file:close()
if reactor == "true" then
rednet.send(reactorCom, "on")
elseif reactor == "false" then
rednet.send(reactorCom, "off")
end
elseif result == false then
rednet.send(reactorCom, "off")
end
while true do
display()
event, param1, param2, param3 = os.pullEvent()
if event == "rednet_message" then
if param2 == "heat" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
temp = b
elseif param2 == "reactorPoweredB" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
reactor = tostring(B)/>/>/>
file = fs.open("rctrStatus", "w")
file.write(B)/>/>/>
file:close()
elseif param2 == "maxHeat" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
maxHeat = b
elseif param2 == "output" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
output = b
elseif param2 == "timeLeft" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
timeLeft = b --*0.00277778
elseif param2 == "energyL" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
energyL = b
energyL = tonumber(energyL)
if energyL > 10000000 then
energyL = 10000000
end
elseif param2 == "maxStorageL" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
maxStorageL = b
elseif param2 == "isSteam" then
rednet.send(nir, "ping")
a,b = rednet.receive(.5)
isSteam = b
end
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(colors.white)
if reactor == "true" then
mon.write("Reactor 1: ")
mon.setTextColor(colors.lime)
mon.write("ON")
mon.setTextColor(colors.white)
elseif reactor == "false" then
mon.write("Reactor 1: ")
mon.setTextColor(colors.red)
mon.write("OFF")
mon.setTextColor(colors.white)
else
mon.write("Reactor 1: "..reactor)
end
mon.setCursorPos(1,3)
tempPercent = temp / maxHeat
tempPercent = tempPercent*100
tempPercent = math.floor(tempPercent)
mon.write("Reactor Temp: "..temp.."c")
mon.setCursorPos(1,5)
mon.write("EU Output: "..output)
mon.setCursorPos(1,7)
mon.write("Fuel: "..timeLeft)
mon.setCursorPos(1,9)
mon.write("Shutdown Temp: "..shutTemp)
mon.setCursorPos(21, 1)
mfsuE = tonumber(energyL)
mfsuEL = tonumber(maxStorageL)
if mfsuE == mfsuEL then
mon.write("MFSU: 100%")
else
mfsuPercent = mfsuE / mfsuEL
mfsuPercent = mfsuPercent*100
mfsuPercent = math.floor(mfsuPercent)
mon.write("MFSU: "..mfsuPercent.."%")
end
-- mon.setCursorPos(21, 3)
-- mon.write("EU: "..mfsuE)
elseif event == "monitor_touch" then
if param2 > x-6 and param3 < 4 then
if reactor == "false" then
rednet.send(reactorCom, "on")
elseif reactor == "true" then
rednet.send(reactorCom, "off")
end
j,k = rednet.receive()
if j == reactorCom and k == "false" then
for i = 1,4 do
mon.setBackgroundColor(colors.red)
mon.clear()
mon.setTextScale(4)
mon.setTextColor(colors.black)
mon.setCursorPos(1, 2)
mon.write("OVERHEATING!")
os.sleep(.5)
mon.clear()
mon.setTextColor(colors.red)
mon.setBackgroundColor(colors.black)
mon.setCursorPos(1, 2)
mon.write("OVERHEATING!")
os.sleep(.5)
end
end
mon.setTextScale(1)
mon.setBackgroundColor(colors.black)
mon.setTextColor(colors.lime)
rednet.broadcast("ping")
elseif param3 == y then --and param2 * 2 * 100 < 7500 then
adjustTemp = param2 * 2 * 100
mon.setCursorPos(param2, param3)
mon.setBackgroundColor(1)
mon.write(" ")
mon.setBackgroundColor(colors.black)
rednet.send(reactorCom, "maxTemp")
id, message = rednet.receive()
if id == reactorCom then
adjustTemp = tostring(adjustTemp)
rednet.send(reactorCom, adjustTemp)
id, message = rednet.receive()
if message == "true" and id == reactorCom then
shutTemp = adjustTemp
file = fs.open("shutTemp", "w")
file.write(shutTemp)
file:close()
elseif message == "false" and id == reactorCom then
mon.setCursorPos(1,y)
for i = 1,x do
mon.write(" ")
end
mon.setCursorPos(1,y)
mon.write("Max Temp Failed To Update!")
end
end
end
end
end
Edited on 23 April 2014 - 08:42 PM