AccessorFunc

From Garry's Mod
Jump to: navigation, search
 AccessorFunc( )

Contents

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

table tab

The table to add the accessor functions too.

Arguments

any key

The key of the table to be get/set.

Arguments

string name

The name of the functions (will be prefixed with Get and Set).

Arguments

number force=nil

The type the setter should force to (uses FORCE_ Enums).

Examples

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)

local ply = player.GetByID(1)
ply:SetFooBar(true)

print(not ply:GetFooBar())

Output:

false
Personal tools
Navigation