Checking for a Nil value from a table.
Posted: Fri Jan 18, 2013 2:56 pm
Yesterday I made this post: viewtopic.php?f=3&t=12376
In said post, I asked about Nil vs False, and decided to make air a nil value (in my table) to save memory. I did this without any problems.
Unfortunately, I am not able to check if a certain value from my table is nil or not! I have tried the following bits of code, and can't get them to work.
You get the picture, I have also tried doing some things I googled such as using Next, but I couldn't find a solution to my problem.
If anyone can give me code or tell my where I might find code that could help me, I would be very grateful.
Thank you very much
--Luska72
PS: I was able to check if a variable is Nil without problems, so I think Lua works like this:
Lua directly compares the variable to nil
Lua first grabs the value from the table, then compares to nil.
However, the program crashes when grabbing the value from the table, so we can't compare to nil...
In said post, I asked about Nil vs False, and decided to make air a nil value (in my table) to save memory. I did this without any problems.
Unfortunately, I am not able to check if a certain value from my table is nil or not! I have tried the following bits of code, and can't get them to work.
Code: Select all
if level[y][x] ~= nil then
Code: Select all
if not level[y][x] == nil then
Code: Select all
item = level[y][x]
if item ~= nil then
Code: Select all
item = level[y][x]
if not item == nil then
If anyone can give me code or tell my where I might find code that could help me, I would be very grateful.
Thank you very much
--Luska72
PS: I was able to check if a variable is Nil without problems, so I think Lua works like this:
Code: Select all
If VARIABLE == NIL
Code: Select all
If TABLE[Y][X] == NIL
However, the program crashes when grabbing the value from the table, so we can't compare to nil...