Jump to content




Nuclear Reactor Automation ERROR Help!


5 replies to this topic

#1 Sharpie

  • Members
  • 3 posts

Posted 20 February 2017 - 06:20 AM

I have created a program and infrastructure which automates a MK. 5 IC2 Nuclear Reactor, by replacing damaged items when they reach a certain threshold of damage and have the reactor do a full refuel and recycle every now and then (540 items replaced).

Whenever I have left it to just run and idle I come back to see my program has crashed which is very dangerous because the reactor could explode if im not there to turn it off, so I have come to receive some help with reviewing my code and helping me understand where I am going wrong. I am also using AE2 and OpenPeripherals for this setup.

local setup = { 0, 1, 0, 1, 0, 1, 0, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 2 }

local reactor = peripheral.wrap("top")
local storage = peripheral.wrap("tileinterface_4")
local recycler = peripheral.wrap("tileinterface_5")
local full = true

local x = 1
local loops = 1

local lzhF = { id = "IC2:item.reactorCondensatorLap", dmg = 0, }
local uranF = { id = "IC2:item.reactorUraniumQuad", dmg = 0, }
local overF = { id = "IC2:item.reactorVentGold", dmg = 0, }

local function reFuel(check)
if x == 1 then
  x = 0
  loops = 0
  rs.setOutput("front", false)
  
  if check then
   for o = 1, 54 do
	recycler.pullItem("north", o, 1, 1)
   end
  end

  for i = 1, 54 do
  
   if setup[i] == 0 then
	storage.exportItem(lzhF, "south", 1, i)
   elseif setup[i] == 1 then
	storage.exportItem(uranF, "south", 1, i)
   elseif setup[i] == 2 then
	storage.exportItem(overF, "south", 1, i)
   end
  
  end
	rs.setOutput("front", true)
end
end

while true do
term.clear()
term.setCursorPos(1,1)
full = rs.getInput("back")
-- MAIN

print("Running: " .. tostring(reactor.isActive()))
print("Heat: " .. reactor.getHeat())
print("Loops:" .. loops)

if reactor.getHeat() >= 100 then
  rs.setOutput("front", false)
  for y = 1, 54 do
   recycler.pullItem("north", y, 1, 1)
  end
elseif reactor.getHeat() < 100 then
  rs.setOutput("front", true)
end

if reactor.isActive() and reactor.getHeat() < 100 then
  
  for w = 1, 54 do

   if loops > 540 then
	rs.setOutput("front", false)
	x = 1
   end
	
   if reactor.getStackInSlot(w) ~= nil then
	if setup[w] == 0 then
	 if reactor.getStackInSlot(w).id == "IC2:item.reactorCondensatorLap" and reactor.getStackInSlot(w).dmg > 50000 then
	  loops = loops + 1
	  recycler.pullItem("north", w, 1, 1)
	  storage.exportItem(lzhF, "south", 1, w)
	 end
	elseif setup[w] == 1 then
	 if reactor.getStackInSlot(w).id == "IC2:item.reactorUraniumQuad" and reactor.getStackInSlot(w).dmg > 7500 then
	  loops = loops + 1		  
	  recycler.pullItem("north", w, 1, 1)
	  storage.exportItem(uranF, "south", 1, w)
	 end
	end
   elseif reactor.getStackInSlot(w) == nil then
	if setup[w] == 0 then
	 storage.exportItem(lzhF, "south", 1, w)
	elseif setup[w] == 1 then
	 storage.exportItem(uranF, "south", 1, w)
	end
   end
  end
end

if full == true then
  x = 1
elseif full == false and x == 1 then
  if next(reactor.getAllStacks()) == nil then
   reFuel(false)
   x = 0
  else
   reFuel(true)
   x = 0
  end
end

-- MAIN
os.queueEvent("fakeEvent")
os.pullEvent()
end

The error says something along the lines of "nuclear:69: error getting TileEntity at dim 0 ..."

#2 Bomb Bloke

    Hobbyist Coder

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

Posted 20 February 2017 - 10:03 AM

View PostSharpie, on 20 February 2017 - 06:20 AM, said:

The error says something along the lines of "nuclear:69: error getting TileEntity at dim 0 ..."

Not your error, exactly; that's been thrown by whatever peripheral mod is letting you wrap the reactor (OpenPeripherals, presumably). Basically it's saying that it can't read the reactor data for some reason. Consider whether the reactor's chunk would ever unload while the computer's code is active, for starters.

#3 Sharpie

  • Members
  • 3 posts

Posted 21 February 2017 - 01:17 AM

Well the weird thing is I have a chunk loader within the chunk spanning out 2 chunks around the system, but its down at bedrock and 100 blocks under the reactor, does it need to be like in the reactor because thats fine if I need to do that.

#4 Bomb Bloke

    Hobbyist Coder

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

Posted 21 February 2017 - 11:33 PM

That sounds fine as far as the chunk loading side of things goes. You might still try ensuring that the reactor itself (and the modem attached to it) aren't crossing any chunk boundries (chunk loaded or not), but if that doesn't help then you probably won't be able to resolve the underlying fault.

I suppose you could wrap up the content of your main loop into a function, and then pcall that; if you ever detect an error, display a message accordingly, sleep for a few seconds maybe, then attempt it again.

local function loopStuff()
	term.clear()
	term.setCursorPos(1,1)
	full = rs.getInput("back")
	-- MAIN

	-- etc
	.
	.
	.
end

while true do
	local success, message = pcall(loopStuff)
	
	if not success then
		term.setCursorPos(1,1)
		term.setTextColour(colours.red)
		term.setBackgroundColour(colours.black)
		term.clear()
		term.write(message)
		
		sleep(10)
	end
end


#5 Sharpie

  • Members
  • 3 posts

Posted 24 February 2017 - 05:56 AM

is there any way i could be able to store the error message into a file on the computer because if it keeps refreshing then sleeping i wont be able to see the message when the chunk loading stuffs up

#6 Bomb Bloke

    Hobbyist Coder

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

Posted 28 February 2017 - 09:11 AM

Sure:

.
.
.

if not success then
  local output = fs.open("errorLog.txt", "a")
  output.writeLine(message)
  output.close()
  .
  .
  .






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users