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

Tempermental Monitors

Started by andreblue, 30 August 2015 - 05:52 PM
andreblue #1
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
   
   
Lupus590 #2
Posted 30 August 2015 - 08:57 PM
Changing the font size is a common solution to monitors misbehaving.
Bomb Bloke #3
Posted 31 August 2015 - 12:42 AM
That is to say, CC 1.74's monitors are a little buggy, and doing the above kicks them back into gear.

Note you have to change the text scale. Merely setting it to the same value it's already set to does nothing. Feel free to change it back to whatever value you actually want to use after tweaking it, though.