Posted 17 April 2016 - 06:18 PM
Hey there,
I was writing a help function for one of my programs that would be displayed whenever no arguments were provided.
This is what I tried:
The result was that calling the program without any arguments would return an "Attempt to call index? (a nil value)" error
while literally anything as an argument (or multiple for that matter) would trigger the if-statement and display the text.
The first reaction I can understand as I did attempt to call a nil value but the other I'm confused by.
How can I correctly check for a nil value when I expect it to be there?
I was writing a help function for one of my programs that would be displayed whenever no arguments were provided.
This is what I tried:
local arg = (...)
-- help
if arg[1] == nil then
print("text")
error()
end
The result was that calling the program without any arguments would return an "Attempt to call index? (a nil value)" error
while literally anything as an argument (or multiple for that matter) would trigger the if-statement and display the text.
The first reaction I can understand as I did attempt to call a nil value but the other I'm confused by.
How can I correctly check for a nil value when I expect it to be there?