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

Sending table over rednet is always nil

Started by voidraizer, 28 August 2016 - 01:26 AM
voidraizer #1
Posted 28 August 2016 - 03:26 AM
Hello,

I'm struggling to get a program I found on here working (http://www.computerc...onitor-program/).

For some reason, in the receiver, the table exists but the subcomponents are always nil. I consistently get an error saying ".temp:28: attempt to index ? (a nil value) when checking mes.active.

The code for the receiver:

-- program to print valuable information
-- about reactor

rednet.open("right")
local mon = peripheral.wrap("left")
local protocol = 1
term.redirect(mon)
term.clear()

while true do
local id, mes, pro = rednet.receive(protocol, 5)
term.redirect(mon)
term.clear()
sleep(0.5)
term.setCursorPos(1,1)
mon.setTextScale(0.5)
if mes == false then
  write("STATUS: ")
  mon.setBackgroundColor(colors.red)
  write("ERROR")
  mon.setBackgroundColor(colors.black)
  print()
  print()
  print("Something is wrong with program or reactor setup")
  print("Hold Ctrl+T to terminate program")
else
  write( "STATUS: ")
  if mes.active == true then
	mon.setBackgroundColour(colors.lime)
	write("ACTIVE")
  elseif mes.active == false then
	mon.setBackgroundColour(colors.yellow)
	write("NOT ACTIVE")
  end
  mon.setBackgroundColor(colors.black)
  print()
  print()
  print("Energy Production: " .. math.floor(mes.energyOutput,0) .. " EU/t")
  print("Tank Info; " .. mes.tankInfo .. " RF")
  print()
  print("Temperature: " .. mes.reactorTemp .. " C")
  print("Max Temperature: " .. mes.reactorMaxTemp .. " C")
end
sleep(0.1)
end

code for the sender:

-- program to monitor reactor health
rednet.open("left")
local reactor = peripheral.wrap("right")
local protocal = 1

while true do
  works = reactor.isValid()
  if works == false then
	rednet.broadcast(works, protocol)
	sleep(0.1)
  else
	--ractive = reactor.isActive()
	--rheat = reactor.getHeat()
	--rmheat = reactor.getMaxHeat()
	--reuout = reactor.getEUOutput()
	--rtank = reactor.getTankInfo()
	local mytable =
	{
	  active = reactor.isActive(),
	  reactorTemp = reactor.getHeat(),
	  reactorMaxTemp = reactor.getMaxHeat(),
	  energyOutput = reactor.EUOutput
	  --tankInfo = rtank
	}
	rednet.broadcast(mytable,protocol)
	sleep(0.1)
  print(mytable.active)
  print(mytable.reactorTemp)
  print(mytable.reactorMaxTemp)
  print(mytable.energyOutput)
  print(mytable.tankInfo)
  end
end
KingofGamesYami #2
Posted 28 August 2016 - 01:17 PM
What version of computercraft do you have? Some versions didn't allow sending tables over rednet directly.
voidraizer #3
Posted 28 August 2016 - 04:32 PM
I'm using the latest Infinity Evolved pack on Curse and it says it has ComputerCraft1.75.jar
KingofGamesYami #4
Posted 28 August 2016 - 04:49 PM
In that case, I bet rednet.receive is timing out (you have it set to 5 seconds) and returning nil.

If it returns nil, you try to index it because it's not false.
voidraizer #5
Posted 28 August 2016 - 05:31 PM
But the sender and the receiver are only a few blocks apart and the sender should be sending several times a second. How can the receiver be timing out? I've also tried increasing the timeout to as much as 30 seconds and it still times out.

Sorry for these late responses. I had to create a new account for this and I have to wait for my posts to be approved
Edited on 28 August 2016 - 06:59 PM
TheRockettek #6
Posted 28 August 2016 - 08:48 PM
oh ik protocol isnt defined but protocal is defined d: line 4 sender

local protocal = 1
voidraizer #7
Posted 28 August 2016 - 11:25 PM
oh ik protocol isnt defined but protocal is defined d: line 4 sender

local protocal = 1

Thank you!! This was the problem. Thank you with the eagle eyes
plazter #8
Posted 01 September 2016 - 03:12 PM
on a side note, its a big reactor program, and makes RF, if you want it in EU you need to recalculate it down dont you?
1 EU = 4 RF


EDIT: im being a derp sorry :P/>
Edited on 01 September 2016 - 01:13 PM
TheRockettek #9
Posted 01 September 2016 - 11:18 PM
the rf/eu ratio is different for different modpacks. Eg: its 1eu/10rf in tekkit classic