Garry's Mod Wiki

Garry's Mod Wiki

What is self

self is just a quality of life variable added in Lua that represents whatever the function is called on. Lua automatically creates this variable when defining functions with the : symbol.

hopefully you know how variable assigning works and if you don't, read Beginner_Tutorial_Variables

Here is an example:

-- Using Lua Syntactical Sugar function myTable:anyFunction( arg1 ) PrintTable( self ) end -- Using Literal Definitions myTable.anyFunction = function( self , arg1 ) PrintTable( self ) end

The only difference between the ways are defined is if we let Lua define self for us, or if we want to define it ourselves

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...