Hello!
I've just built a BigReactor in my current FTB Monster 1.1.2 world and I wanted something to automatically control it. I remembered that the last world I played on (which had something like 24, 7x7x7 reactors) each had a computer attached to it with a reactor control program that I'd gotten from the internet. I think it was this forum, though it could've been the CC one or just from Googling. Unfortunately, I can't find the code itself anywhere and I'm not even sure if it IS the code I used because I don't remember having any monitors plugged in.
Here's the code (THIS CODE IS NOT MINE):
I'm getting an error "attempt to call nil" on line 141 which is: "term.restore()" on the penultimate line, there.
This code was used just fine on Monster V1.1.1 many months ago (if it's what I think it is), so has something changed with any of the mods, or is there something obvious I'm doing wrong? Thanks!
I've just built a BigReactor in my current FTB Monster 1.1.2 world and I wanted something to automatically control it. I remembered that the last world I played on (which had something like 24, 7x7x7 reactors) each had a computer attached to it with a reactor control program that I'd gotten from the internet. I think it was this forum, though it could've been the CC one or just from Googling. Unfortunately, I can't find the code itself anywhere and I'm not even sure if it IS the code I used because I don't remember having any monitors plugged in.
Here's the code (THIS CODE IS NOT MINE):
Code:
-- Basic control for BigReactors-Reactor
-- BSD3 License
-- Emily Backes <[email protected]>
-- Uses the first monitor it finds, if any
-- May need 3x3 or larger for that
-- No log output or printer usage yet
-- Will work on adv comps but mouse event handling
-- would need to be added below
-- Suitable for use in /startup
-- Max energy in a reactor's internal cell
local emax=10000000
-- wrap everything in an exception handler
local ok,msg=pcall(function ()
local r
local m
local redirected=false
local p
function findDev (dType)
local d
for _,d in pairs(peripheral.getNames()) do
if (peripheral.getType(d) == dType) then
return peripheral.wrap(d)
end
end
return nil, dType..": not found"
end
function setupDevs()
r=assert(findDev("BigReactors-Reactor"))
if (not r.getConnected()) then
return nil, "Computer port not connected to a valid reactor"
end
--if (r.getNumberOfControlRods() <1) then
-- return nil, "Reactor seems invalid"
--end
r.getEnergyPercent = function ()
return math.floor(1000 * r.getEnergyStored() / emax)/10
end
if r.nativeEPLT then
r.getEnergyProducedLastTick = r.nativeEPLT
end
r.nativeEPLT = r.getEnergyProducedLastTick
r.getEnergyProducedLastTick = function ()
return math.floor(r.nativeEPLT()*1000)/1000
end
if redirected then
term.restore()
redirected = false
end
m=findDev("monitor")
if m then
m.setTextScale(1)
term.clear()
term.setCursorPos(1,1)
print("Redirecting to attached monitor")
term.redirect(m)
redirected = true
end
term.setCursorBlink(false)
p=findDev("printer")
end
function ft ()
local d=os.day()
local t=os.time()
local h=math.floor(t)
local m=math.floor((t-h)*60)
return string.format("Day %d, %02d:%02d",d,h,m)
end
function log (msg)
local stamp=ft()
print (stamp..": "..msg)
end
function tableWidth(t)
local width=0
for _,v in pairs(t) do
if #v>width then width=#v end
end
return width
end
function ljust(s,w)
local pad=w-#s
return s .. string.rep(" ",pad)
end
function rjust(s,w)
local pad=w-#s
return string.rep(" ",pad) .. s
end
function display()
term.clear()
term.setCursorPos(1,1)
print("Reactor Status")
print(ft())
print("")
local funcs={"Connected","Active","NumberOfControlRods","EnergyStored","EnergyPercent","Temperature","FuelAmount","WasteAmount","FuelAmountMax","EnergyProducedLastTick"}
local units={"","","","RF","%","C","mB","mB","mB","RF/t"}
local values={}
for _,v in pairs(funcs) do
values[#values+1] = tostring(r["get"..v]())
end
local funcW=tableWidth(funcs)
local valW=tableWidth(values)
for i,v in pairs(funcs) do
print(rjust(v,funcW)..": "..rjust(values,valW).." "..units)
end
end
log("Starting")
setupDevs()
while true do
local e=r.getEnergyStored()
local p=math.floor(100*e/emax)
local a=p<100
local elt=r.getEnergyProducedLastTick()
display()
r.setAllControlRodLevels(p)
r.setActive(a)
os.startTimer(0.8333334)
local event,p1,p2,p3,p4,p5 = os.pullEvent()
if event == "key" then
break
elseif event == "peripheral_detach" or event == "peripheral" or event == "monitor_resize" then
setupDevs()
elseif not (event == "timer" or event=="disk" or event=="disk_eject") then
error("received "..event)
end
end
end)
term.restore()
error(msg)
I'm getting an error "attempt to call nil" on line 141 which is: "term.restore()" on the penultimate line, there.
This code was used just fine on Monster V1.1.1 many months ago (if it's what I think it is), so has something changed with any of the mods, or is there something obvious I'm doing wrong? Thanks!