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

[1.58][SSP] Getting Error "Unabled to create new native thread" when running script

Started by Dr. Console, 22 April 2014 - 12:36 AM
Dr. Console #1
Posted 22 April 2014 - 02:36 AM
Hey guys,
today i wrote a script for controling the a reactor build with big reactors mod.
The reactor can be wraped as peripheral.
So i wrote a script for keepig it at a difined temperature.
But after 6 cycles in the loop it fails an gives the error "unabled to create new native thread".
Would be great if someone knows already a simple bugfix or so…
I know this version is outdated, but FTB modpacks aren't updated that fast.

I appended the script under this post, found no way to attach it as file, sorry.

NG from Germany
Dr. Console





local reac
local fheat
local hheat
local nrOfRods
local active = false
local emergency = false
local timeover = true
local depthOfRods
local timer
local event
local ID


reac = peripheral.wrap("back")
nrOfRods = reac.getNumberOfControlRods()
controlRods(100)
function controlRods(amount)
local i = 0
if not emergency then
begin
  for i=0, nrOfRods do
  reac.setControlRodLevel(i,amount)
end
end

function setActive(val)
if (reac.getActive() ~= val) and (emergency == false) then
  reac.setActive(val)
return reac.getActive()
end

function emergencyAutomatic()
if (fheat > 2200) then
begin
  print("Emergency shutdown! Fuel heat over 2200°C")
  controlRods(100)
  emergency = true
end
if (emergency == true) and (fheat == 0) then
begin
  emergency = false
end
end

function heatControl()
if timeover then
begin
  if (fheat<=1000) and (hheat<1500) then
  begin
   controlRods((depthOfRods – 5))
   print("Info: Decreasing depth of rods by 5%")
   timer = os.startTimer(10)
  end
  if (fheat<2000) and (fheat>1000) and (hheat<1500) then
  begin
   controlRods((depthOfRods – 1))
   print("Info: Decreasing depth of rods by 1%")
   timer = os.startTimer(5)
  end
  if (fheat>2050) or (hheat>1600) then
  begin
   controlRods((depthOfRods + 10))
   timer = os.startTimer(5)
   print("WARNING: Fuel heat over 2050°C or casing heat over 1600°C , Encreasing depth of rods by 10%")
  end
timeover = false
end
end

function timerFinished()
if (ID == timer) then
  timeover = true
end
end

function main()
fheat = reac.getFuelTemperature()
hheat = reac.getCasingTemperature()
depthOfRods = reac.getControlRodLevel(1)
active = rs.getInput("right")
emergencyAutomatic()
setActive(active)
heatControl()

end

function timerEvent()
event,ID = os.pullEvent("timer")
end
while true do
local func = parallel.waitForAny(main, timerEvent)
if (func == 2) then
begin
  timerFinished()
end
end
Lyqyd #2
Posted 23 April 2014 - 09:31 PM
You're creating an awful lot of coroutines by continually calling parallel.waitForAny. There may be an underlying issue that also could use addressing, but you may be able to avoid the error by re-designing your program to loop inside just two coroutines instead of creating new ones constantly. That is, put a while loop inside each of the functions you run in parallel and take out the one surrounding the parallel call. You might be interested in posting over in Ask a Pro if you have trouble changing it over. Making that change should stop the issue from popping up. You'd want to make the same change in any other code you're running that does similar things.

Also, I am not aware of a "begin" keyword in Lua, so I'm not sure why that isn't throwing errors for you.