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

Program exits randomly

Started by beninjapan, 09 April 2012 - 04:49 PM
beninjapan #1
Posted 09 April 2012 - 06:49 PM
Hello, everyone!

I have been having a rather weird problem with one of my scripts.
The script uses ccSensors to automatically measure the nuclear reactor temperature and automatically shut it down if it reaches a critical threshold using RedPower with a bundled cable.

The script itself is a rather simple one


os.loadAPI("/rom/apis/sensors")

local side = sensors.getController()
local monitor = peripheral.wrap("right")
local controlCable = "left"
local reactorOverride = colors.black
local reactorId = "1A"
local reactorPower = 0
local stopUpdating = false

function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

function printStatus()

local dataResult = sensors.getReading(side, "ReactorHeat" .. reactorId, "heat", "maxheat", "output")
local heatPercentage = round(dataResult.heat/dataResult.maxheat*100, 1);

local reactorStatus = "Offline"
if (colors.test(redstone.getBundledInput("front"), reactorOverride)) then
  reactorPower = 0
  reactorStatus = "Offline"
else
  reactorPower = 1
  reactorStatus = "Online"
end

term.redirect(monitor)

-- Emergency Shutdown
if (heatPercentage > 90.0) then
  redstone.setBundledOutput("front", reactorOverride)
elseif (heatPercentage < 40.0) then
  redstone.setBundledOutput("front", colors.white)
end
print("==========================")
print("Single Chamber Control")
print("==========================")
print("")
print("Reactor ID: " .. reactorId)
print("Reactor Status: "..reactorStatus)
print("")
print("Reactor Heat: "..dataResult.heat.."   ("..heatPercentage.."%)")
print("Output: "..dataResult.output.." EU/t")
print("Ice Storage: ")
print("")
print("")
print("")
print("")
print("")
print("")
print("")

end

while true do
printStatus()
sleep(1)
end

Which I suppose should work fine. However, the script seems to be exiting randomly even though it is in a while loop. In the best case I make 3 loops (3 seconds) which is not really helpful for a reactor.
If I remove the printStatus function from the while loop the script executes without problems.

Any ideas why this script is not working?
beninjapan #2
Posted 10 April 2012 - 06:19 PM
Bump ^-^
Hawk777 #3
Posted 13 April 2012 - 07:22 AM
There’s no error message? Does this only happen if you walk away? When chunks are unloaded any running programs in unloaded computers will stop, and when you come back into range the computer will do a fresh bootup. Or does it happen when you’re standing right in the area?