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

Reactor Attempt to call nil

Started by ArcNelkul, 17 May 2015 - 05:49 PM
ArcNelkul #1
Posted 17 May 2015 - 07:49 PM
I am just confused. I normally wouldn't even consider myself inexperienced at coding, and I have been trying to find out what I'm doing wrong here for almost an hour. I literally have 4 lines:


args = {...}
level = tonumber(args[1])
reactor = peripheral.wrap("back")
reactor.setAllControlRodLevels(level)

I was actually replicating a piece of code I had already written yesterday, since it was on a server and I wanted to test my system while the server was down. I am pretty sure this is exactly what I had written, but there is apparently a possibility I haven't written this right. I have already tested if the args table works correctly, which it does. I have also made sure that the back of the computer is adjacent to the computer port on the reactor. It's just the function: setAllControlRodLevels() that's not working for some reason. The error message is as follows:


>cr 90
cr:4: attempt to call nil
valithor #2
Posted 17 May 2015 - 09:36 PM
It appears that either the setAllControlRodLevels function does not exist for the peripheral, or it is not being wrapped correctly.

Run the lua program, and run the following:

print(peripheral.getMethods("back"))

This will get all of the functions of the peripheral on the given side. If it prints functions, then check to see if the setAllControlRodLevels function is one of them, and make sure you spelt it correctly.

If it does not print anything, then there is no wrappable peripheral on that side of the computer. Which means you will have to make sure the reactor itself is on the correct side and is set up correctly to be wrapped as a peripheral.
Edited on 17 May 2015 - 07:37 PM
flaghacker #3
Posted 17 May 2015 - 09:38 PM
That function probably doesn't exist. Make sure you typed it correctly. You can check the functions that do exist via this code:

for k in pairs (peripheral. wrap ("back") do
  print (k)
end

If it isn't in there then it simply doesn't exist.

Edit: :ph34r:/>
Edited on 17 May 2015 - 07:40 PM
Bomb Bloke #4
Posted 18 May 2015 - 12:23 AM
If it does not print anything, then there is no wrappable peripheral on that side of the computer. Which means you will have to make sure the reactor itself is on the correct side and is set up correctly to be wrapped as a peripheral.

Sorta worth noting that if there were no valid peripheral to wrap, peripheral.wrap("back") would return nil, and so line four would throw an attempt to index nil error.