Jump to content




window:52: Too long without yielding

peripheral lua computer

3 replies to this topic

#1 Simmons928

  • Members
  • 10 posts

Posted 20 June 2014 - 06:14 AM

I just finished the program I am going to use to automate my Reactor and it runs great until I get the error "window:52:to long with out yielding"

I would like to know if there is a way I can get around this.

This the is function that I need to infinite loop.
function startAutomation()
local continue = 1
reactor.setAllControlRodLevels(conRodLvl)
while continue==1 do
connected = tostring(reactor.getConnected())
numOfContRod = reactor.getNumberOfControlRods()
active = tostring(reactor.getActive())
powerStore = reactor.getEnergyStored()
fuelTemp = reactor.getFuelTemperature()
caseTemp = reactor.getCasingTemperature()
currentFuel = reactor.getFuelAmount()
amountWaste = reactor.getWasteAmount()
maxFuel = reactor.getFuelAmountMax()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
rodLevel = reactor.getControlRodLevel(0)
print("The reactor is now managing itself")
print("---------------------------------------------------")
print("Connected? "..verCon.."|-----------------------|Active? "..verAct)
print("Number of Control rods in reactor? "..numOfContRod)
print("Fuel in reactor: "..currentFuel.."/"..maxFuel)
print("Fuel Temp: "..fuelTemp.."|---|Casing Temp: "..caseTemp)
print("Fuel use per Tick: "..fuelUsed)
print("Energy p/tic: "..energyProd.."|-|Power Stored: "..powerStore)
print("Fuel reactivity: "..fuelReact.."|-|Control Rod Level: "..rodLevel)
if caseTemp>maxCaseTemp then
continue = 2
redstone.setOutput("left", true)
else
if fuelTemp>maxFuelTemp then
  continue = 2
  redstone.setOutput("back", true)
else
  if powerStore<minPower then
   rodLevel = rodLevel -  1
   reactor.setAllControlRodLevels(rodLevel)
   sleep(5)
  elseif powerStore>maxPower then
   rodLevel = rodLevel + 1
   reactor.setAllControlRodLevels(rodLevel)
  else
   sleep(1)
  end
end
end
os.eventQueue("char","p")
end
end


Full Program
reactor = peripheral.wrap("right")
-- Standard Reactor Vars
connected = reactor.getConnected()
numOfContRod = reactor.getNumberOfControlRods()
active = reactor.getActive()
powerStore = reactor.getEnergyStored()
fuelTemp = reactor.getFuelTemperature()
caseTemp = reactor.getCasingTemperature()
currentFuel = reactor.getFuelAmount()
amountWaste = reactor.getWasteAmount()
maxFuel = reactor.getFuelAmountMax()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
rodLevel = reactor.getControlRodLevel(0)
--Vars used in automation
conRodLvl = 100
maxPower = 7500000
minPower = 5000000
maxCaseTemp = 700
maxFuelTemp = 2500
-- Coolant Vars
--reactor.getHotFluidProducedLastTick
--reactor.getCoolantType
--reactor.getCoolantAmount
--reactor.getHotFluidType
--reactor.getHotFluidAmount
--reactor.isActivelyCooled
function basicInfo() -- reports the basic information for the reactor
local selectValue = 0 -- local var for while test
while selectValue==0 do
connected = tostring(reactor.getConnected())
numOfContRod = reactor.getNumberOfControlRods()
active = tostring(reactor.getActive())
powerStore = reactor.getEnergyStored()
fuelTemp = reactor.getFuelTemperature()
caseTemp = reactor.getCasingTemperature()
currentFuel = reactor.getFuelAmount()
amountWaste = reactor.getWasteAmount()
maxFuel = reactor.getFuelAmountMax()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
rodLevel = reactor.getControlRodLevel(0)
term.clear()
print("You have selected to view the basic information.")
print("Please wait...")
print("OK!!")
print("----------------------------------------------")
if connected=="false" then -- check if reactor is connected for menu
  verCon = "are not"
else
  verCon = "are"
end
print("You "..verCon.." connected to the reactor.")
if active==nil then -- check if reactor is active for menu
  verAct = "is not"
else
  verAct = "is"
end
print("The reactor "..verAct.." running")
print("Number of control rods: "..numOfContRod)
print("Amount of power stored: "..powerStore)
print("Current temp of fuel in the reactor: "..fuelTemp)
print("Current casing temp: "..caseTemp)
print("Current amount of fuel(Current/Max): "..currentFuel.."/"..maxFuel)
print("type 'return' to be brought back to the main menu")
print("type 'refresh' to update the values above")
local input = read()
if input == "return" then -- check if to refresh values or to go back to main menu
  selectValue = selectValue + 1
elseif input == "refresh" then
  basicInfo()
else
  print("Please enter the a valid option!")
end
end
end
function manualAdjust()
print("you have reached Manual Adjustments.")
print("There is currently no function for this option.")
print("You will be returned to the main menu")
sleep(5)
end
function advInfo()
print("you have reached Advanced Information.")
print("There is currently no function for this option.")
print("You will be returned to the main menu")
sleep(5)
end
function setAutoValue()
local selectValue = 1
term.clear()
print("You have selected to configure the limits for reactor automation.")
print("Please wait while we pull the current config.")
print("Loading config...")
sleep(3)
print("Ready!!")
while selectValue==1 do
print("Below you will see the current values:")
print("To change value enter the number at the start of the selection.")
print("1: Starting control rod level is: "..conRodLvl)
print("2: Maximum power stored: "..maxPower)
print("3: Minimum power stored: "..minPower)
print("4: Maximum casing temp: "..maxCaseTemp)
print("5: Maximum fuel temp: "..maxFuelTemp)
print("6: Return to main menu.")
local input = tonumber(read())
if input==1 then
  term.clear()
  print("Starting level is currently: "..conRodLvl)
  print("What is the new level? ")
  local newCLvl = tonumber(read())
  conRodLvl = newCLvl
  print("New starting level set to: "..conRodLvl)
  print("Saving..")
  sleep(1)
  term.clear()
elseif input==2 then
  term.clear()
  print("The current maximum reserve power is set to: "..maxPower)
  print("What is the new maximum? ("..minPower.."-10000000)")
  local newPLvl = tonumber(read())
  maxPower = newPLvl
  print("New maximum power reserve: "..maxPower)
  print("Saving..")
  sleep(1)
  term.clear()
elseif input==3 then
  term.clear()
  print("The current minimum reserve power is set to: "..minPower)
  print("What is the new minimum? (0-"..maxPower..")")
  local newPLvl = tonumber(read())
  minPower = newPLvl
  print("New minimum power reserve: "..minPower)
  print("Saving..")
  sleep(1)
  term.clear()
elseif input==4 then
  term.clear()
  print("The current maximum temp the casing can")
  print("reach before the reactor stops: "..maxCaseTemp)
  print("what is the new maximum casing temp?")
  local newCTemp = tonumber(read())
  maxCaseTemp = newCTemp
  print("New maximum casing temp is: "..maxCaseTemp)
  print("Saving..")
  sleep(1)
  term.clear()
elseif input==5 then
  term.clear()
  print("The current maximum temp the fuel can")
  print("reach before the reactor stops: "..maxFuelTemp)
  print("what is the new maximum casing temp?")
  local newCTemp = tonumber(read())
  maxFuelTemp = newCTemp
  print("New maximum fuel temp is: "..maxFuelTemp)
  print("Saving..")
  sleep(1)
  term.clear()
elseif input==6 then
  print("returning..")
  sleep(1)
  term.clear()
  selectValue = 2
else
  term.clear()
  print("Please enter the a valid option!")
end
end
end
function startAutomation()
local continue = 1
reactor.setAllControlRodLevels(conRodLvl)
while continue==1 do
connected = tostring(reactor.getConnected())
numOfContRod = reactor.getNumberOfControlRods()
active = tostring(reactor.getActive())
powerStore = reactor.getEnergyStored()
fuelTemp = reactor.getFuelTemperature()
caseTemp = reactor.getCasingTemperature()
currentFuel = reactor.getFuelAmount()
amountWaste = reactor.getWasteAmount()
maxFuel = reactor.getFuelAmountMax()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
rodLevel = reactor.getControlRodLevel(0)
print("The reactor is now managing itself")
print("---------------------------------------------------")
print("Connected? "..verCon.."|-----------------------|Active? "..verAct)
print("Number of Control rods in reactor? "..numOfContRod)
print("Fuel in reactor: "..currentFuel.."/"..maxFuel)
print("Fuel Temp: "..fuelTemp.."|---|Casing Temp: "..caseTemp)
print("Fuel use per Tick: "..fuelUsed)
print("Energy p/tic: "..energyProd.."|-|Power Stored: "..powerStore)
print("Fuel reactivity: "..fuelReact.."|-|Control Rod Level: "..rodLevel)
if caseTemp>maxCaseTemp then
continue = 2
redstone.setOutput("left", true)
else
if fuelTemp>maxFuelTemp then
  continue = 2
  redstone.setOutput("back", true)
else
  if powerStore<minPower then
   rodLevel = rodLevel -  1
   reactor.setAllControlRodLevels(rodLevel)
   sleep(5)
  elseif powerStore>maxPower then
   rodLevel = rodLevel + 1
   reactor.setAllControlRodLevels(rodLevel)
  else
   sleep(1)
  end
end
end
os.eventQueue("char","p")
end
end
function mainReactor() -- core function for the program
local selectValue = 0 -- local var for while test
while selectValue==0 do -- While to make sure proper selection is made
print("Reactor Automation and Control")
print("By SimAssassin")
print("v1.0.1")
print("Welcome to my reactor automation and control software!")
print("Please select one of the below options by entering the number")
print("---------------------------------------------------")
print("1: Basic Information - Temp/Fuel/Stored Power/Produced Power")
print("-: Manual Adjustment")
print("-: Advanced Information - Coolant Level/Type/Used")
print("4: Set Automation values")
print("5: Start Automation")
print("6: Exit program")
local input = tonumber(read())
if input==1 then -- Selection Menu if statement
  basicInfo()
  term.clear()
elseif input==2 then
  manualAdjust()
  term.clear()
elseif input==3 then
  advInfo()
  term.clear()
elseif input==4 then
  setAutoValue()
  term.clear()
elseif input==5 then
  startAutomation()
  term.clear()
elseif input==6 then
  print("Goodbye and thank you for using my software")
  selectValue = selectValue + 1
else
  term.clear()
  print("Please enter the a valid option!")
end
end
end
mainReactor()


#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 20 June 2014 - 10:28 AM

Moved to Ask A Pro.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 20 June 2014 - 11:20 AM

When a computer/turtle starts running code, ComputerCraft starts a ten second timer. If that code doesn't yield before that timer ends then ComputerCraft crashes that computer. After each yield, processing continues with a new time limit.

The reason why is that running your code chews up valuable server processing power, and so it shouldn't be able to monopolise it. In fact, only ONE CC device can run code at a time: While one is doing something, none of the others can do anything until it yields.

Whether or not it takes more then ten seconds for your code to execute has a lot to do with the power of the Minecraft server it's running on, and how often you allow your code to yield. Pulling events (eg getting typed characters) or sleeping triggers a yield, and many commands (eg turtle movements or getting text input from the user) have to pull events to work anyway.

Your loop runs flat out, only pausing under certain criterias. I suggest adding a sleep(1) (or perhaps even a higher value) into the loop that'll be called on every iteration.

#4 Simmons928

  • Members
  • 10 posts

Posted 21 June 2014 - 03:31 AM

View PostBomb Bloke, on 20 June 2014 - 11:20 AM, said:

When a computer/turtle starts running code, ComputerCraft starts a ten second timer. If that code doesn't yield before that timer ends then ComputerCraft crashes that computer. After each yield, processing continues with a new time limit.

The reason why is that running your code chews up valuable server processing power, and so it shouldn't be able to monopolise it. In fact, only ONE CC device can run code at a time: While one is doing something, none of the others can do anything until it yields.

Whether or not it takes more then ten seconds for your code to execute has a lot to do with the power of the Minecraft server it's running on, and how often you allow your code to yield. Pulling events (eg getting typed characters) or sleeping triggers a yield, and many commands (eg turtle movements or getting text input from the user) have to pull events to work anyway.

Your loop runs flat out, only pausing under certain criterias. I suggest adding a sleep(1) (or perhaps even a higher value) into the loop that'll be called on every iteration.

Thank! I did add the sleep(1). I had been staring at this for probable 2-3 hours getting all the kinks out and I accidentally deleted the sleep and did not notice it





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users