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

Loading an API, attempt to index ? (a nil value)

Started by Adamski1997, 10 May 2017 - 10:23 PM
Adamski1997 #1
Posted 11 May 2017 - 12:23 AM
Hi,

below is the simplified code that is causing the issue (I don't believe you need any more code than this, there is a lot of it!)

main:


os.loadAPI("GUI")
function main()
   --Lots of code
   local username, password = GUI.runLogin("")
end
main()

GUI:

--Some code
function runLogin(msg)
   --Lots of code
   return username, password
end

The error I get seems to occur on the compiler pass, since no print statements in either the GUI or main files get printed before the error is thrown.

The exact error I get is: "main:29: attempt to call index ? (a nil value)" (In the minified example I've given you the one an only line in the main function is the one that throws the error)

Any idea how to fix this? I don't know what is wrong with the way I've done this..

(Yes both main and GUI are in the exact same directory on the computer)
Edited on 10 May 2017 - 10:26 PM
KingofGamesYami #2
Posted 11 May 2017 - 12:58 AM
First, I would figure out if GUI is actually loading. os.loadAPI returns a boolean value stating whether or not the API has been loaded.
Adamski1997 #3
Posted 11 May 2017 - 01:07 AM
Well for some reason adding the code to print if the API is loaded or not fixed it. Even after reverting the code back to its original state it now works, so no idea what solved it but thanks!