I have been talking to my dad and asked him what exactly nil was. He wasn't exactly sure and maybe you guys can answer me on that one. What exactly is the difference between nil and null and when is something nil or null?
When Is Something Nil And Null?
Started by GamerNebulae, Aug 04 2013 10:19 AM
3 replies to this topic
#1
Posted 04 August 2013 - 10:19 AM
#2
Posted 04 August 2013 - 10:47 AM
a variable is nil when a value has not been assigned to it... nil is a keyword, just like null is a keyword in other languages, used to mean the same thing...
also as makerimages stated in Lua nil actually resolves to false, meaning that your if statements could be structured like so
instead of
also as makerimages stated in Lua nil actually resolves to false, meaning that your if statements could be structured like so
if someVar then --# do something end
instead of
if someVar ~= nil then --# do something end
#3
Posted 04 August 2013 - 01:51 PM
The only distinctions between nil and null are their respective spellings and which languages they're used in.
#4
Posted 04 August 2013 - 06:51 PM
In Lua, nonexistent table entries act as if they have the value nil. It's also the default value for global variables (which are really table entries) and local variables.
t = {test=123}
print(tostring(t["test"])) -- prints: 123
print(tostring(t["hello"])) -- prints: nil
print(tostring(asdf)) -- prints: nil
local x
print(tostring(x)) -- prints: nil
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











