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

[SOLVED]Attempt to index ? (a nil value)

Started by Rangicus, 09 September 2012 - 05:11 PM
Rangicus #1
Posted 09 September 2012 - 07:11 PM
I am making an api xAPI,


function getTree()
if turtle.detect() then
  turtle.dig()
  turtle.digUp()
  turtle.up()
end
while turtle.detectDown() == false do
  turtle.down()
end
end
function downStair(arg1)
function dig()
turtle.dig()
turtle.up()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnRight()
end
dig()
a = 1
repeat
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.dig()
turtle.forward()
a = a + 1
until a == arg1
(This is only the function I need help with the rest of my api is peachy)
(also the values in this function are not used in any other functions)
Anyways it is supposed to make a 2x2 staircase according to how deep you want it (arg1),
but it returns -Attempt to index ? (a nil value)-,
and all my values are either 0 or another value,\
I checked none of them are nil.
Help?
EDIT:When I call the function I go into lua and type 'xAPI.downStair(64)'
EDIT:The error is on line 1 O.o
Lyqyd #2
Posted 09 September 2012 - 07:13 PM
Please post the whole code, and the whole error (especially the line number).
Rangicus #3
Posted 09 September 2012 - 07:24 PM
Please post the whole code, and the whole error (especially the line number).
There I posted the whole code and the line number
Lyqyd #4
Posted 09 September 2012 - 07:39 PM
With the error being on line one, the problem is either that the API is not loaded, or that the call to the function is malformed. Also, you are missing an end at the end of the downStair function, so the API may be failing to load because of that. Make sure the API is loading correctly.
PixelToast #5
Posted 09 September 2012 - 08:20 PM
EDIT:When I call the function I go into lua and type 'xAPI.downStair(64)'
EDIT:The error is on line 1 O.o
thats it,
line 1 means the error is from the command itself, not the api
its calling nil probably because the api isnt being loaded
if your not putting xAPI in mods/ComputerCraft/lua/rom/apis/ then you have to load it manually:

os.loadAPI(path)
any errors thrown by that command are syntax errors that prevent it from being loaded or an incorrect filename
the file name also has to be exactly xAPI
sjele #6
Posted 09 September 2012 - 08:21 PM
Make sure to remove .txt extension if you made the file externaly
PixelToast #7
Posted 09 September 2012 - 08:26 PM
Make sure to remove .txt extension if you made the file externaly
also with np++ it will automatically change the file extention to the syntax highlighting, its a bit annoying because you have to select all files every time you want to make a new file
Rangicus #8
Posted 09 September 2012 - 08:28 PM
I used np++ and changed the file type to all files, and it is in rom/apis i am not stupid lol
sjele #9
Posted 09 September 2012 - 08:43 PM
I belive it get's an extension then. That mean you need to call it like this xAPI.(extension).(function)
PixelToast #10
Posted 09 September 2012 - 08:55 PM
I belive it get's an extension then. That mean you need to call it like this xAPI.(extension).(function)
no, it said attempt to index a nil value not call a nil value
when an api is loaded its environment is saved into a table
sence the API is not being loaded when the inturpreter runs xAPI.<name> it errors because xAPI is nil

you probably have the name wrong or are putting it in the wrong folder
the name of the file has to be exactly xAPI, windows hides known file extentions by default, you have to make sure its disabled
MysticT #11
Posted 09 September 2012 - 09:14 PM
I think it's not loading due to an error in the api (as Lyqyd said, there's a missing end in it).
Try doing

os.pullEvent("/rom/apis/xApi")
from the lua prompt. If there's any errors loading it you will know.
Rangicus #12
Posted 09 September 2012 - 10:58 PM
I belive it get's an extension then. That mean you need to call it like this xAPI.(extension).(function)
no, it said attempt to index a nil value not call a nil value
when an api is loaded its environment is saved into a table
sence the API is not being loaded when the inturpreter runs xAPI.<name> it errors because xAPI is nil

you probably have the name wrong or are putting it in the wrong folder
the name of the file has to be exactly xAPI, windows hides known file extentions by default, you have to make sure its disabled
OMG Thank you I changed the name from xAPI to xapi and it worked. Thank you. *Likes*