FANDOM


NilEdit

EssentialsEdit

Nil is short for non-initialized value, meaning its just an empty value. This means that if you expect a value and it isn't there, then it will be nil.

SamplesEdit

Sample
If a table index cannot be found, then nil will be returned.

Source:

local table = {'Foo'}
print(table[2])
Output:

nil


Sample
If a variable doesn't exist, then nil will be returned.

Source:

print(variable)
Output:

nil


ExtraEdit

In actuality, nil is only returned in two instances. This is when and index from a table doesn't exist and if a function returns nil. What about variables? Well really that's the same as indexing from the environment which is a table. What about assigning nil to a variable? You cannot initialize a non-initialized value. Take a look.

Sample
Is there any real change?

Source:

print(x)
local x = nil
print(x)
Output:

nil
nil


See, nothing changed, nothing was initialized, the variable stayed the same.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.