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 Enums/FORCE).


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) local ply = Entity( 1 ) ply:SetFooBar(true) print(not ply:GetFooBar())
Output: false