Nil

From Legacy Roblox Wiki
Revision as of 18:21, 9 March 2010 by >Mr Doom Bringer
Jump to navigationJump to search

Nil is a noninitialized value, or lack of a value, that is blank and equal to nothing. 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 :Remove() function, it is removed from the game completely by setting its parent to nil. Unless the object is referenced, it cannot be recovered.

Uses

Nil can be used to remove the value of a property of an object. It is very common to set the parent of an object to "Nil", removing it from the game per se. If the object is referenced by a variable for example, you can 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, your health will go to 0 and you will gain a wipeout.

See Also


Absolute beginner's guide to scripting
Parts
Script Creation Walkthrough
Programming in Lua:1.2 - Global Variables
Programming in Lua:2.1 - Nil
Null