What does runtime error bad argument #1 to pairs (table expected, got nil) mean?
Asked by
AshlynM (
10684)
July 29th, 2016
I got this message while playing a game app on my ipad. I could close the app and restart it just fine. What does this message mean?
Observing members:
0
Composing members:
0
4 Answers
It means that the programmer of the game made a mistake while writing the code.
At some point, there is a function called “pairs” being run, and it has an input that should be of the data type “table”, but the function got run with “nil” as an input instead (nil is basically a null value). The function does not know what to do with this input so its only option is to crash, which is what a runtime error is.
@Mariah Has it right.
My best guess: the programmer has prematurely told the program that it doesn’t need the “table” object anymore and so that table object gets destroyed and removed from memory. There may be a reference to that table that’s being passed in to the pairs function as one of it’s argument. The reference “thinks” there’s a table there but it’s gone—it’s like saying got to mailbox 5 and you’ll find a table but when you open it up you find nothing, or a piece text, or a color, or something else that’s NOT a table. At some point prior the system was told it was done with the table in mailbox 5 and could put whatever it wanted in there, so when the function went to look for “table” there it didn’t find a table and crashed with an error.
I“m not sure if that made things more confusing or less. In programming we refer to this type of error as an “Over-release of memory.”
Somewhat aside from @Mariah‘s response, while the developer may have written the code to function properly “when properly directed by the user”, you as the user may have skipped an input or step that the program requires for proper function. And in that case, the program encountered an unexpected error and crashed.
It’s still a programming error, because the programmer should have bullet-proofed his program with proper error-handling routines to account for all potential and likely user errors, such as informing the user that a step has been skipped, an input ignored, or some other user error has occurred which the user needs to rectify.
Programming isn’t all that difficult. Error trapping and handling is a bitch.
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.