3 posts
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/fTiz6hhbThanks in advance
P.S. the code is for an automatic train server if folk are interested.
1190 posts
Location
RHIT
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.
3 posts
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.
997 posts
Location
Wellington, New Zealand
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.
997 posts
Location
Wellington, New Zealand
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.
3 posts
Posted 03 October 2013 - 11:35 AM
Many thanks indeed folks, appears to be working fine now. You guys are great!