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

help! Been up all night...

Started by cornmanv2, 30 July 2015 - 06:25 AM
cornmanv2 #1
Posted 30 July 2015 - 08:25 AM
So I'm playing direwolf20 1.5.0 with big reactors. I wanted to make a controling program for it well my program failed terribly.. When ever I try and run it I get this error

BIOS :367: [string "reactors"] '<name>' expected

I have no idea how to correct this.
Balthamel #2
Posted 30 July 2015 - 03:53 PM
Post your code.
apemanzilla #3
Posted 30 July 2015 - 04:00 PM
Sounds like you added a stray equals sign somewhere, or some unexpected data. Post your code so we can help.
LuckyLuke #4
Posted 30 July 2015 - 04:54 PM
Don't forget to post your code as well as your error.
We cannot give 100%, if we dont know every possibility :)/>
cornmanv2 #5
Posted 30 July 2015 - 05:04 PM
Spoiler
--
-- Control passive cooled Big Reactor ([url="http://big-reactors.com/"]http://big-reactors.com/[/url]).
--
-- Author: Cornmanv2
--
-- History:
--	 v0.1, 2015-07-30:
--		 first version
--
-- Remarks:
--	 Reactor API: [url="http://big-reactors.com/cc_api.html"]http://big-reactors.com/cc_api.html[/url]
--

--
-- Constant values (configuration)
--

-- Critical energy mark: give us the maximum power.
critEnergy=3000000

-- Low energy mark: turn reactor on to get more energy
lowEnergy=7000000

-- Heigh energy mark: we have enough, so turn the reactor off.
highEnergy=9000000


--
-- Calculate the control rod level (in %) by stored energy of internal
-- recator cell.
--
-- * If cellEnergy <= critEnergy, the calculation results in maximum
--   energy generation (control rod level = 0%).
-- * If cellEnergy >= highEnergy, the calculation results in 10% energy
--   generation (control rod level = 90%).
--
-- Parameters:
--	 cellEnergy - stored energy of internal cell in RF
--
-- Return:
--	 New control rod level in %.
--
function calcRodLevel(cellEnergy)
   -- Delta between critical and heigh energy mark
   local deltaEnergy = highEnergy - critEnergy

   -- Calculated maximum delta energy (not the real maximum), so that
   -- the high energy mark results into a control rod level of 90%
   local deltaEnergy100 = deltaEnergy * 100 / 90

   -- Energy for calculation: value between 0 and 'deltaEnergy'
   local calcEnergy = cellEnergy - critEnergy

   if calcEnergy < 0 then
	  calcEnergy = 0
   elseif calcEnergy > deltaEnergy then
	  calcEnergy = deltaEnergy
   end

   -- Calculate control rod level and round the result (math.floor + 0.5)
   return math.floor(calcEnergy * 100 / deltaEnergy100 + 0.5)
end


--
-- Write text with colors, if possible (advance monitor)
--
-- Parameters:
--	 mon   - handle of monitor
--	 color - text color
--	 text  - text to write
--
function writeColor(mon, color, text)
   if (mon.isColor()) then
	  mon.setTextColor(color)
   end
   mon.write(text)
   if (mon.isColor()) then
	  mon.setTextColor(colors.white)
   end
end


--
-- Display reactor status to a monitor.
--
-- Parameters:
--	 mon		- handle of monitor.
--	 state	  - state of reactor (on/off)
--	 rodLvl	 - Level of control rods in %
--	 cellEnergy - stored energy of internal cell (in RF)
--
function displayStatusToMonitor(mon, state, rodLvl, cellEnergy)
   mon.clear()

   -- First get the monitor size and try to scale, if the feature ist
   -- available.
   if mon.setTextScale ~= nil then
	  -- reset text scale
	  mon.setTextScale(1)
   end

   local width, height = mon.getSize()
   if width < 15 or height < 5 then
	  -- too small: try to scale down.
	  if mon.setTextScale ~= nil then
		 mon.setTextScale(0.5)
	  else
		 return -- too small und no text scale available
	  end

	  width, height = mon.getSize()
	  if width < 15 or height < 5 then
		 return -- still too small
	  end
   else
	  -- Huge monitors? Try to scale up, if possible (max scale=5).
	  local scale = math.min(width / 16, height / 5, 5)
	  scale = math.floor(scale * 2) / 2 -- multiple of 0.5

	  if scale > 1 and mon.setTextScale ~= nil then
		 mon.setTextScale(scale)
		 width, height = mon.getSize()
	  end
   end


   --
   -- Output the data
   --

   mon.setCursorPos(1,1)
   mon.write("Reactor")

   mon.setCursorPos(1,3)
   mon.write("Status ")

   if state then
	  writeColor(mon, colors.green, "ON")
   else
	  writeColor(mon, colors.red, "OFF")
   end

   mon.setCursorPos(1,4)
   mon.write("Rod Level: " .. rodLvl .. "%")

   mon.setCursorPos(1,5)
   if width < 16 then
	  mon.write("Cell: ") -- One block monitor (15x5 with scale 0.5)
   else
	  mon.write("Energy: ")
   end

   local c
   if cellEnergy < critEnergy then
	  c = colors.red -- Red: We use too much energy
   elseif cellEnergy > lowEnergy then
	  c = colors.green -- Green: More energy then low water mark
   else
	  c = colors.orange -- Orange: Less energy the low water mark, but OK
   end
   writeColor(mon, c, string.format("%d", math.floor(cellEnergy/1000 + 0.5)))
   mon.write(" kRF")
end


--
-- Display reactor status to any connected monitor and also to console.
--
-- Parameters:
--	 state	  - state of reactor (on/off)
--	 rodLvl	 - Level of control rods in %
--	 cellEnergy - stored energy of internal energy cell in RF
--
function displayStatus(state, rodLvl, cellEnergy)
   displayStatusToMonitor(term, state, rodLvl, cellEnergy) -- console
   term.setCursorPos(1,7)
   term.write("* Hold Crtl-T to terminate program")
   term.setCursorPos(1,8)

   local pList = peripheral.getNames()
   local i, name
   for i, name in pairs(pList) do
	  if peripheral.getType(name) == "monitor" then
		 -- found monitor as peripheral
		 displayStatusToMonitor(peripheral.wrap(name),
								state, rodLvl, cellEnergy)
	  end
   end
end


--
-- Find the first connected big reactor and return the wraped handle.
--
-- If no reactor was found this function terminate the program.
--
-- Return:
--	 Handle of first connected reactor found.
--
function getReactorHandle()
   local pList = peripheral.getNames()
   local i, name
   for i, name in pairs(pList) do
	  if peripheral.getType(name) == "BigReactors-Reactor" then
		 return peripheral.wrap(name)
	  end
   end

   error("No big reactor connected: Exit program")
   exit()
end


reactor = getReactorHandle()

--
-- Endless loop: Recalculate rod level, set rod level, display result
-- and wait for 5 secounds.
--
while true do
   cellEnergy = reactor.getEnergyStored()
   if cellEnergy < lowEnergy then
	  -- Low energy: switch reactor ON and calculate control rods by
	  -- energy cell level.
	  reactor.setActive(true)
	  rodLvl=calcRodLevel(cellEnergy)
   elseif cellEnergy > highEnergy then
	  -- High energy: switch reactor OFF and set control rod level to 100
	  reactor.setActive(false)
	  rodLvl=100
   elseif cellEnergy > lowEnergy then
	  -- Enough energy: do not change state of reactor. Only recalculate
	  -- control rod level.
	  --
	  -- * If the reactor ist switched off, we will wait until energy
	  --   fall below low energy mark.
	  --
	  -- * If it is turned on, we generate more energy until the
	  --   energy level exeeds the high energy mark.
	  rodLvl=calcRodLevel(cellEnergy)
   end

   reactor.setAllControlRodLevels(rodLvl)

   displayStatus(reactor.getActive(), rodLvl, cellEnergy)

   os.sleep(5) -- Wait for 5s
end

--
-- EOF
--
Edited by
cornmanv2 #6
Posted 30 July 2015 - 07:06 PM
So now I have the Bios error I know have

Attempt to perform arithmetic __mull on nil and number
MKlegoman357 #7
Posted 30 July 2015 - 09:39 PM
That's the error, but we need the full error message, which also includes the line number on which the error occurred, including the name of the program or API the error occurred in.
cornmanv2 #8
Posted 30 July 2015 - 09:54 PM
Reactors:49: attempt to perfrom arthmetic __mul on nil number
Bomb Bloke #9
Posted 31 July 2015 - 02:43 AM
Within the actual script file the computer is trying to run, double check the spelling of "deltaEnergy" on lines 49 and 45. If they look fine post the current version of the script.
cornmanv2 #10
Posted 31 July 2015 - 02:49 AM
Ok thanks!… But now another one ( I'm not gonna try and write programs again hah)

Error
Reactors:132: attempt to call nil
cornmanv2 #11
Posted 31 July 2015 - 03:00 AM
Ok nevermind that fixed that error.
Now this
Reactors:79: attempt to ondex? (a number value)
Bomb Bloke #12
Posted 31 July 2015 - 03:13 AM
You've defined something as a number and you're trying to index it like it were a table.

Hard to elaborate further without seeing the code in concern.
cornmanv2 #13
Posted 31 July 2015 - 03:22 AM
This is the codes lines from 66 to 81
– Parameters:
– mon - handle of monitor
– color - text color
– text - text to write

function writeColor(mon, color, text)
if (mon.isColor()) then
mon.setTextColor(color)
end
mon.write(text)
if (mon.isColor()) then
mon.setTextColor(colors.white)
end
end
Edited on 31 July 2015 - 01:39 AM
cornmanv2 #14
Posted 31 July 2015 - 04:02 AM
http://pastebin.com/nXr7TUQk
Lyqyd #15
Posted 31 July 2015 - 04:26 AM
That error shouldn't be possible with that script. You successfully index both the colors API and the mon object immediately before the problematic line, and nothing in that script ever assigns any new values to the colors API. I suspect that this is not an exact match for the script that's actually erroring.
cornmanv2 #16
Posted 31 July 2015 - 05:05 AM
Ok fixed that now. I'm really sorry for all this.. Frist time doing this.

:144: attempt to call nil
Lyqyd #17
Posted 31 July 2015 - 05:25 AM
And the latest code, please?
cornmanv2 #18
Posted 31 July 2015 - 05:31 AM
http://pastebin.com/aEWtTjUz
Lyqyd #19
Posted 31 July 2015 - 05:45 AM
Looks like it didn't completely copy.