Posted 30 August 2015 - 07:52 PM
I have the below code which for some reason only sometimes wants to write to the monitor. I have done it with wraping and with finding and can never really reproduce the same issue each time. is there anything you see that could cause the issue?
local reactor = peripheral.find("BigReactors-Reactor")
local monitor = peripheral.wrap("monitor_1")
print(tostring(monitor))
local function percentMe(currentValue, maxValue)
return math.floor((100*currentValue)/maxValue)
end
local status
local statusColor
term.redirect(monitor)
while true do
local maxPower = 10000000
local storedPower = math.floor(reactor.getEnergyStored())
local powerPercent = percentMe(storedPower, maxPower)
local maxFuel = math.floor(reactor.getFuelAmountMax())
local fuelStored = math.floor(reactor.getFuelAmount())
local fuelPercent = percentMe(fuelStored, maxFuel)
local wasteStored = math.floor(reactor.getWasteAmount())
local wastePercent = percentMe(wasteStored, maxFuel)
local casingHeat = reactor.getCasingTemperature()
local coreHeat = reactor.getFuelTemperature()
local perTickGen = reactor.getEnergyProducedLastTick()
--control our reactor
if powerPercent > 80 then
reactor.setActive(false)
else
reactor.setActive(true)
end
--do monitor thins
term.clear()
term.setBackgroundColor(colors.black)
term.setCursorPos(1,1)
term.setTextColor(colors.white)
term.write("Reactor Status: ")
term.setCursorPos(17,1)
if reactor.getActive() then
statusColor = colors.lime
status = "Online"
else
statusColor = colors.red
status = "Offline"
end
term.setTextColor(statusColor)
term.write(status)
term.setCursorPos(1,2)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.write("Reactor Fuel(%): " .. tostring(fuelPercent))
term.setCursorPos(1,3)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.write("Reactor Waste(%): " .. tostring(wastePercent))
term.setCursorPos(1,4)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.write("Reactor Power: " .. tostring(storedPower) .. " RF(" .. tostring(powerPercent) .. "%)")
term.setCursorPos(1,5)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.write("Fuel Temperature(C): " .. tostring(math.floor(coreHeat)))
term.setCursorPos(1,6)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.write("Hull Temperature(C): " .. tostring(math.floor(casingHeat)))
term.setCursorPos(1,7)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.write("RF Per Tick(RF): " .. tostring(math.floor(perTickGen)))
sleep(5)
end