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

Ftp:121: Attempt To Call Nil (But The Variables Are Not Nil!)

Started by DaGamer12345, 04 August 2013 - 09:41 PM
DaGamer12345 #1
Posted 04 August 2013 - 11:41 PM
Basically, when I try to send a serialized table over rednet (Unrelated note: I probably will switch to the modem api), it says that one (or both) of the variables is nil. But the variable seems to be assigned (NOTE: I did take some code from the list program, so idk why this shouldn't work)

The program is here: http://pastebin.com/CSYKKQjM (An FTP client/server)

Again, the full error is "ftp:121: attempt to call nil" (I honestly hope this is a complicated issue and not a derp moment which every programmer has)

Also, sorry the file isn't well-commented. I wasn't planning on posting the code until it was mainly bug-free. Hopefully you can understand it.

Another thing: For some reason, if the server is stopped, all functions cannot be used until the computer is restarted. Any thoughts?

Anyway, any help on this will be greatly appreciated. :)/>/
DaGamer12345 #2
Posted 05 August 2013 - 12:49 AM
Explaining the code:
Server receives a message, it checks to see if the directory specified is a directory. It is, then pools files and dirs into separate tables (on line 121, apparently either the file or the table doesn't exist, which is impossible), serializes them, and then sends them over rednet to have them unserialized and listed. If the directory is not given, it will list the root directory, and if the directory doesn't exist, it will explicitly say that. So it is impossible for no files to be in the table, and impossible for the table to not exist. That's where I'm confused.

I will try to print the table when I can get to my computer (unless someone makes a CC emulator for Android in a short amount of time).
EDIT: I printed out the variables, neither were nil for some reason. The program is just being a derp and not inserting the value into the table (dirs work for some odd reason).
Engineer #3
Posted 05 August 2013 - 08:29 AM
I found the problem on line 32. You are redefining the variable called table, now it it holds the output from the http call and it doesnt hold the table with the table functions. So if you change the variable of line 32 it should work correctly again.
DaGamer12345 #4
Posted 05 August 2013 - 09:57 AM
Will try to fix that using your solution when I can get to my computer,Engineer. It seems weird that CC can't tell you WHICH variable is nil, but that a variable on that line is nil.
EDIT:But that would mean that 119 would be nil as well, but it has no issue.
LBPHacker #5
Posted 05 August 2013 - 10:18 AM
Will try to fix that using your solution when I can get to my computer,Engineer. It seems weird that CC can't tell you WHICH variable is nil, but that a variable on that line is nil.
EDIT:But that would mean that 119 would be nil as well, but it has no issue.
No it wouldn't. If we can see that line 121 is trying to be executed, that means that 119 just won't, since it's the other branch of the IF.
DaGamer12345 #6
Posted 05 August 2013 - 10:36 AM
But if a dir is added to the table (or when line 119 gets executed) it works fine for some reason, even though it's similar to the file one. Why one works and the other other doesn't, I'm not sure.
Engineer #7
Posted 05 August 2013 - 10:46 AM
The other one wont work, because it errors out at one of them. Try to call a table API before the whole system -> it will error.
LBPHacker #8
Posted 05 August 2013 - 11:03 AM
But if a dir is added to the table (or when line 119 gets executed) it works fine for some reason, even though it's similar to the file one. Why one works and the other other doesn't, I'm not sure.
Then do us a favor and view the file in the built-in edit, that way we can be sure if the problem is actually with the table.* calls. And do change the table variable in getTime to something else.

Oh, by the way. I thought I was clear when I said that http://artemix.hu/cctime.php is not there to be fetched in every seconds. You fetch the time once, and you have to increment it yourself from that on. I might apply something that prevents people from fetching the time from my site in every second or so.

Well, I tried to press Submit, but it felt wrong to end this time-topic this way. I think I'm going to post an IRL time API.
DaGamer12345 #9
Posted 05 August 2013 - 11:18 AM
Oh, by the way. I thought I was clear when I said that http://artemix.hu/cctime.php is not there to be fetched in every seconds.
It's only temporary, I will have it increment itself before the program goes public (if it does).
I will change the table variable to something else when I can test the code.
[Also, use in-game editor to look at the code when I can see it on pastebin? Why?]
Engineer #10
Posted 05 August 2013 - 11:33 AM
[Also, use in-game editor to look at the code when I can see it on pastebin? Why?]
Because it might be different in the meantime.
DaGamer12345 #11
Posted 05 August 2013 - 02:38 PM
The list error is now fixed, which subsequently fixed having to reboot the computer after stopping the server. But, since having to ping the cctime site could slow it down if done in large amounts, how would I get to making it ping once and then just increment it in the background? I tried using os.pullEvent() with timers and their ID's, but that did not work. If I followed the code from here, it couldn't receive commands or other events.