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

Attempt to call Nil when function exists

Started by Tieran02, 17 January 2016 - 01:36 PM
Tieran02 #1
Posted 17 January 2016 - 02:36 PM
I am coding a program that will sent big reactor information via rednet to another computer that will display it on a screen. however for some reason i get the attempt to call nil error when calling the function sentWater() and SentSteam() but sentTemp() and sendFuel() work and the code is near identical the only difference is the string that is being send via rednet. can anyone help me out please?

code: http://pastebin.com/sUHy9qVW

local reactor = peripheral.wrap("top")
local controlID = 7
local active = false
function listen()
  rednet.open("left")
  while true do
	id, msg = rednet.receive()
	if msg == "Reactor true" then
	  active = true
	  print(msg)
	elseif msg == "Reactor false" then
	  active = false
	  print(msg)
	end
  end
end
function main_loop()
  while true do
	os.queueEvent("randomEvent")
	os.pullEvent()
	sendDetails()
	if active == false then
	  reactor.setActive(false)
	else
	  reactor.setActive(true)
	end			
  end
end
function sendTemp()
  rednet.send(controlID, "Reactor 1 temperature = " .. reactor.getFuelTemperature())
end
function sendFuel()
  rednet.send(controlID, "Reactor 1 fuel amount = " .. reactor.getFuelAmount() .. "/" .. reactor.getFuelAmountMax())
end
function sentWater()
  rednet.send(controlID, "Reactor 1 water level = " .. reactor.getCoolantAmount() .. "/" .. reactor.CoolantAmountMax())
end
function sentSteam()
  rednet.send(controlID, "Reactor 1 steam level = " .. reactor.getHotFluidAmount() .. "/" .. reactor.getHotFluidAmountMax())
end
function sendDetails()
  sendTemp()
  sendFuel()
  sendWater()
  sendSteam()
  sleep(1)
end
parallel.waitForAll(listen, main_loop)

error: reactorTransmiter:52: attempt to call nill
Bomb Bloke #2
Posted 17 January 2016 - 09:57 PM
Line 52:

sendWater()

"sendWater" is hence nil.

Sure enough, on line 41 you're defining a "sentWater" function, but you never define "sendWater".
davidpartay #3
Posted 17 January 2016 - 10:36 PM
Also, when you are defining sentWater, shouldn't it be calling:

reactor.getCoolantAmountMax()

rather than

reactor.CoolantAmountMax()

I can't check for sure at the moment as the wiki page appears to be down.
Tieran02 #4
Posted 20 January 2016 - 10:00 AM
Line 52:

sendWater()

"sendWater" is hence nil.

Sure enough, on line 41 you're defining a "sentWater" function, but you never define "sendWater".
oh wow, i feel so stupid now thanks alot i don't know how i didn't notice that
Tieran02 #5
Posted 20 January 2016 - 10:01 AM
Also, when you are defining sentWater, shouldn't it be calling:

reactor.getCoolantAmountMax()

rather than

reactor.CoolantAmountMax()

I can't check for sure at the moment as the wiki page appears to be down.

Yes it should i fixed that error but forgot to upload the updated pastebin