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

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

Page Links


Special Pages


Wikis

?

Render Time: 42ms

Session 0
DB GetPage 3
Generate Html 15
SaveChanges 11
Render Body 0
Render Sidebar 11