Jump to content




Reactor Attempt to call nil


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

#1 ArcNelkul

  • New Members
  • 1 posts

Posted 17 May 2015 - 06: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


#2 valithor

  • Members
  • 1,053 posts

Posted 17 May 2015 - 08: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 by valithor, 17 May 2015 - 08:37 PM.


#3 flaghacker

  • Members
  • 655 posts

Posted 17 May 2015 - 08: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 by flaghacker, 17 May 2015 - 08:40 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 17 May 2015 - 11:23 PM

View Postvalithor, on 17 May 2015 - 08:36 PM, said:

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.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users