Garry's Mod Wiki

Garry's Mod Wiki

nil Value

nil is Lua's representation of empty data. Unset variables and non-existent table keys will be nil. This will be treated as false in if-statement contexts, but is not equal to false.

See also NULL


print( nil ) print( nil == 0 ) print( nil == 1 ) print( nil == nil ) print( !nil ) -- because nil can be treated like a false boolean in some cases, "not nil" will equal true local myEmptyVariable -- a variable with nothing in it (a 'nil' value) print( myEmptyVariable ) local myTable = { a = "foo", b = "bar" } myTable["a"] = nil -- setting a value in a table to nil effectively erases it from the table PrintTable( myTable )
nil false false true true nil b = bar

Application in VGUI

You can use nil to make some VGUI element transparent.


local menu = vgui.Create( "DFrame" ) menu:SetSize( 300, 200 ) menu:Center() menu:MakePopup() menu:SetTitle( "This is a title" ) local panel = vgui.Create( "DPanel", menu ) panel:Dock( FILL ) panel.Paint = nil

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...