Garry's Mod Wiki


  AccessorFunc( table tab, any key, string name, number force = nil )


Adds simple Get/Set accessor functions on the specified table. Can also force the value to be set to a number, bool or string.


1 table tab
The table to add the accessor functions to.
2 any key
The key of the table to be get/set.
3 string name
The name of the functions (will be prefixed with Get and Set).
4 number force = nil
The type the setter should force to (uses FORCE enum).


Adds the GetFooBar and SetFooBar functions to the Player metatable and then uses them.

local meta = FindMetaTable( "Player" ) AccessorFunc( meta, "foo_bar", "FooBar", FORCE_BOOL ) meta:SetFooBar(true) print(meta:GetFooBar())
Output: true