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

attempt to index ? (a nil value)

Started by ratismal, 21 August 2014 - 12:29 AM
ratismal #1
Posted 21 August 2014 - 02:29 AM
Salutations,

I am currently trying to make a thaumcraft essentia automation/refill system with computercraft. It would entail using a touch-screen monitor to view how much essentia i have of each aspect, and then having the ability to refill the essentia at a click of a button. To do this, I am currently using an edited version of Direwolf20's essentia automation system, however, it is giving me no end of grief.

When run, the program halts with the error

aspect:108: attempt to index ? (a nil value)
I have tried my very best to fix this error myself, however I honestly cannot see what is wrong in the code. I have checked both the program and the button API, both of which I will have included link to below.

In case mod versions are a great factor in this, I am running on the Resonant Rise modpack, on the latest version.

Any help would be greatly appreciated. I have spent all day on this issue, to no avail. However, my knowledge of LUA is simple, at best. I was hoping perhaps a more experienced individual would be able to help me. Thank you in advance.

Sincerely,
Ratismal

Aspects:
http://pastebin.com/9Hy5LvNh
Button API:
http://pastebin.com/p5mpckg0
Bomb Bloke #2
Posted 21 August 2014 - 03:30 AM
The error is saying you're acting like you want to get data from table, but instead of a table, you've asked it to look into an empty variable.

"button" is empty because your API file is saved as "buttonapi". Either change line 108 (and all similar calls) to read:

buttonapi.clearTable()

… or rename the file "buttonapi" to "button" and update line 2 accordingly.
ratismal #3
Posted 21 August 2014 - 04:22 AM
The error is saying you're acting like you want to get data from table, but instead of a table, you've asked it to look into an empty variable.

"button" is empty because your API file is saved as "buttonapi". Either change line 108 (and all similar calls) to read:

buttonapi.clearTable()

… or rename the file "buttonapi" to "button" and update line 2 accordingly.

Ah, I will indeed try this. Originally, the api was simply called 'button'. However, after looking around on the internet for some hints as to how to solve, I decided to change it to 'buttonapi', but forgot to change it throughout the rest of the program.

So, after hearing your advice to change the 'button.' to 'buttonapi.' in my program, I did so. However, upon running the program, I received the same error once again, however this time coming from the buttonapi program, at line 16.
Here is the block in question:

function setTable(name, func, param, xmin, xmax, ymin, ymax)
   button[name] = {}
   button[name]["func"] = func
   button[name]["active"] = false
   button[name]["param"] = param
   button[name]["xmin"] = xmin
   button[name]["ymin"] = ymin
   button[name]["xmax"] = xmax
   button[name]["ymax"] = ymax
end
As far as I can tell, there is nothing wrong with it. As you said, this error generally happens when confronted when the program is confronted the issue of retrieving data from a non-existent table. However, in this case it is refusing to assign a value to this table, and thus make it existent. I have updated the two pastebin files shown in my original post to reflect any changes I have made regarding your advice. Any help would be greatly appreciated in this.

As a side note, I must thank you profusely for helping me the first time. It was much appreciated.

Sincerely,
Ratismal
Bomb Bloke #4
Posted 21 August 2014 - 04:27 AM
Line 16 in the button API file can't throw an attempt to index nil error. Double check that that's the file you're loading as the API (you don't have another file floating around with a similar name by any chance?), and if that doesn't shed any light on the matter, please post the exact wording of the error.
ratismal #5
Posted 21 August 2014 - 10:41 PM
I must thank you for all the help, I have it working now. I'm not sure where that error in the buttonapi file came from, as when I logged in today no such error existed!

I did some mucking about in the file, as there some things that I had changed in the code that didn't save. After doing this, I was confronted with a different error, which I easily fixed. Now my program works perfectly!

Well, less than perfectly, I suppose. At the moment I am having difficulties with it's compatibility with Logistic Pipes. This isn't the fault of any coding, it's the fault of a poor design choice of openperipherals itself. This aside, I would like to greatly thank you for all the help you have provided me with. It was much appreciated, and considering how simplistic my understanding of LUA is, I would have been lost for ages were it not for you! Thank you!

Sincerely,
Ratismal