okay what the hell is wrong with my game

Started by TheTinyDeskEngineer, May 16, 2021, 01:32 PM

Previous topic - Next topic

TheTinyDeskEngineer

I get the error "goggleHost.lua:56: attempt to index local 'file' (a nil value) in a program that's only 33 lines long. It's not because I've misspelled the name, I'm getting the error directly in the edit program.
Maybe I could try restarting minecraft.

TheTinyDeskEngineer

#1
Well, the restart didn't work.
It was worth a shot.

Maybe I can try looking through File Explorer to see if maybe the text file is being shown incorrectly.

TheTinyDeskEngineer

Ok, in Notepad it's a single line longer. That's still not reaching the  line that Computercraft is reporting an error at, though.

I joked about how ridiculous errors can be when programming, and look at where that brought me.

TheTinyDeskEngineer

#3
I created an entirely new program to try and fix this:
local file = fs.open("/goggle/goggleHost.lua", "r")
local text = file.readAll()
if string.find(text, "local file =") ~= nil then
    print("success")
else
    print("nil")
end
file.close()
and, according to  it, the program doesn't have any references of a file variable.
I'll just try searching for "file"

Okay, "file" also returns nil, which means (1) not only is the error lying about how long the program is, it's also (2) lying about there being any file variable at all, or even any of the word "file", which means the "file" variable cannot exist.

TheTinyDeskEngineer

I looked through the program in Notepad yet again, this time using the Find function to find every occurrence of the word "file". There are 3 occurrences of it, two "filepath"s, and one call of the API's newFile function.

Literally the only option I can think of that could possibly do anything meaningful is to restart the computer entirely, and yet that's probably not going to work because I appear to be incapable of seeing something extremely obvious.

Lupus590

When you run a program from edit it saves a file called `.temp`. It could be possible that you are getting issues that way, it's bad to have the file open in CC (say via the edit program) and via a program outside of CC (such as notepad) as they will overwrite each other and basically get their loaded copies out of sync with the actual file.

To be more helpful, we are going to need a link to all of the code of your project and to know what version of CC and MC, and which mod loader you are using.

TheTinyDeskEngineer

pastebin for API and host program:
pastebin get 59jhVuCG goggleHost
pastebin get iqwzSEN1 goggleHost
Minecraft version: 1.12.2
Forge version: 14.23.5.2854
ComputerCraft version: 1.89.1

Lupus590

#7
You seem to have the program and the API names the same. Is it possible that you are looking for the erroring line in the wrong file?

Also, filefile might not open correctly as you don't make sure that the file exists and attempting to open a non-existing file in read mode returns nil instead of a file handle (I think it does at least).

Given that the error message in your OP matches the line that I think is erroring in your API, I am very sure that you are looking in the wrong file. Your program is not the one throwing the error, your API is. I would rename one of the files so that future error messages are clearer.

TheTinyDeskEngineer

I ran the API to make sure I'm not looking in the wrong file, it didn't give an error.

I also have some lines of code in the API's startup function that make sure that the different important files exist, and if not, to create those files.

TheTinyDeskEngineer

I renamed the API to "hostAPI.lua" but the error hasn't changed, so it's absolutely the main program and not the API giving the error.

TheTinyDeskEngineer

I'm trying to print out the variables "mainpath" and "filefile" for debugging purposes, but neither doing it as part of the startup function or as part of the goggleHost program after the startup function is showing anything.
runnging hostAPI isn't giving any errors, despite it being the source of the error goggleHost is giving.

TheTinyDeskEngineer

...and now I add the printing to the end of the API code, and now running it causes the error despite the error refrencing a line which is in a function which isn't called.

Lupus590

Quote from: TheTinyDeskEngineer on May 16, 2021, 11:04 PMI ran the API to make sure I'm not looking in the wrong file, it didn't give an error.
You can't run APIs like programs and expect that to test the code, you have to call every function to test them all.

Quote from: TheTinyDeskEngineer on May 16, 2021, 11:04 PMI also have some lines of code in the API's startup function that make sure that the different important files exist, and if not, to create those files.
I noticed that you didn't have any for filefile

Quote from: TheTinyDeskEngineer on May 16, 2021, 11:07 PMI renamed the API to "hostAPI.lua" but the error hasn't changed, so it's absolutely the main program and not the API giving the error.
Can you post the full error message. A good way is to post a screenshot of the entire CC computer screen.


Quote from: TheTinyDeskEngineer on May 17, 2021, 02:26 AMI'm trying to print out the variables "mainpath" and "filefile" for debugging purposes, but neither doing it as part of the startup function or as part of the goggleHost program after the startup function is showing anything.
I assume that they are printing nil, them being nil is the problem. fs.open returns nil if it can't find the file when opening in read mode. You then attempt to use nil as a file handle resulting in you indexing nil which errors. They are also local to the function and so don't exist after it's ended.


Quote from: TheTinyDeskEngineer on May 17, 2021, 02:33 AM...and now I add the printing to the end of the API code, and now running it causes the error despite the error refrencing a line which is in a function which isn't called.
Link to updated code please, and screenshot of error message.

TheTinyDeskEngineer

I got goggleHost working this morning, now I just need to continue working on it, and once that's done I can start working on the client part.