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

Attempt to call nil - can't find the problem

Started by EJDC, 01 October 2013 - 04:11 PM
EJDC #1
Posted 01 October 2013 - 06:11 PM
Question: Attempt to call nil - can't find the problem.

Hey guys, relatively new to writing programs with lots of functions in them, I've been working on this code for a couple of days and it seems to work, just not all the time. After a reboot I get the error attempt to call nil regarding line 282 when trying to run the program. I've had a look around the forums and I understand I may have the functions in the wrong order. I have played around with the order a quite a bit but with no success.

If anyone is able to help me out and tell me the nature of my fail I'd really appreciate it, my code is here http://pastebin.com/fTiz6hhb

Thanks in advance

P.S. the code is for an automatic train server if folk are interested.
Bubba #2
Posted 01 October 2013 - 08:14 PM
Well your issue is here on line 282:

function destinationpulse(destination,platform)
destination() <- This line
end

You never define destination as a function, so it will fail.
EJDC #3
Posted 01 October 2013 - 08:41 PM
Thanks for the reply,

What I'm trying to do there is make it carry out one of the destination functions (lines 197-272), depending on which is specified in the "destination" local variable at the top. Same for the "cartpulse" function above it. It's purpose is to carry out one of the cart type functions (lines 78 to 195).

The code seems to work fine apart from when running directly after rebooting the computer.
immibis #4
Posted 02 October 2013 - 01:33 AM
Thanks for the reply,

What I'm trying to do there is make it carry out one of the destination functions (lines 197-272), depending on which is specified in the "destination" local variable at the top. Same for the "cartpulse" function above it. It's purpose is to carry out one of the cart type functions (lines 78 to 195).

The code seems to work fine apart from when running directly after rebooting the computer.


local destination = destination1
This is before destination1 is defined, so it takes the value from destination1 (which is nil because you haven't defined it yet) and then sets destination to that.

Move it after destination1 is defined.
immibis #5
Posted 02 October 2013 - 01:35 AM
Thanks for the reply,

What I'm trying to do there is make it carry out one of the destination functions (lines 197-272), depending on which is specified in the "destination" local variable at the top. Same for the "cartpulse" function above it. It's purpose is to carry out one of the cart type functions (lines 78 to 195).

The code seems to work fine apart from when running directly after rebooting the computer.


local destination = destination1
This is before destination1 is defined, so it takes the value from destination1 (which is nil because you haven't defined it yet) and then sets destination to that.

Move it after destination1 is defined.
EJDC #6
Posted 03 October 2013 - 11:35 AM
Many thanks indeed folks, appears to be working fine now. You guys are great!