Nil: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>JulienDethurens
Undo revision 52389 by JulienDethurens (talk)
>JulienDethurens
Undo revision 52389 by JulienDethurens (talk)
(No difference)

Revision as of 21:56, 9 February 2012

What is Nil?

By definition, nil is a state of non-existence or nothingness. In Lua, nil is a non-initialized value, or lack of a value that is equal to nothing. It represents the absense of a useful value. Math cannot be performed on nil or anything equivalent to nil, because nothing, unlike 0, is not a numerical value. When an object is deleted, using the Destroy method, it is removed from the game completely by setting its parent to nil. Unless the object is referenced, it cannot be recovered.

Use Cases

Nil can be used to blank the value of a property of an object (this can only be done with Instance-type properties; you cannot do this to number properties). It is very common to set the Parent of an object to nil, which removes it from the game. However, it is possible to bring the object back. For example, if the object is referenced by a variable, you can set its Parent property again and bring the object back.

Example
{{{1}}}


Look through the comments in the script above to understand why recovering an object by reference is possible.

Here are more examples of "nil" usage:

Example
{{{1}}}


This occurs because setting a players health to "nil" will cause the player to have nothing as a health. Because nothing is similar to having no health at all, you will die.

See Also