Garry's Mod Wiki

AccessorFunc

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

Description

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

Arguments

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

Example

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