Jump to content




Sending table over rednet is always nil


  • You cannot reply to this topic
8 replies to this topic

#1 voidraizer

  • Members
  • 4 posts

Posted 28 August 2016 - 02: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


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 August 2016 - 12:17 PM

What version of computercraft do you have? Some versions didn't allow sending tables over rednet directly.

#3 voidraizer

  • Members
  • 4 posts

Posted 28 August 2016 - 03:32 PM

I'm using the latest Infinity Evolved pack on Curse and it says it has ComputerCraft1.75.jar

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 August 2016 - 03: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.

#5 voidraizer

  • Members
  • 4 posts

Posted 28 August 2016 - 04: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 by voidraizer, 28 August 2016 - 07:59 PM.


#6 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 28 August 2016 - 07:48 PM

oh ik protocol isnt defined but protocal is defined d: line 4 sender

local protocal = 1


#7 voidraizer

  • Members
  • 4 posts

Posted 28 August 2016 - 10:25 PM

View PostTheRockettek, on 28 August 2016 - 07:48 PM, said:

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

#8 plazter

  • Members
  • 134 posts

Posted 01 September 2016 - 02: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 by plazter, 01 September 2016 - 02:13 PM.


#9 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 01 September 2016 - 10:18 PM

the rf/eu ratio is different for different modpacks. Eg: its 1eu/10rf in tekkit classic





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users