G.AccessorFuncNW

From GMod Wiki

Revision as of 18:03, 28 July 2010 by Crazy Quebecer (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax AccessorFuncNW( Table Source Table, String Variable Name, String "Set/Get" Function Name, Var Default Value, Integer Force Type )
Where is this used?
Description:
Quickly make Get/Set accessor fuctions on the specified table. This uses Get- and SetNetworkedVar, and is intended for use with entities or weapons (ENT or SWEP).
Returns: nil
Part of Library: Global Functions
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.AccessorFuncNW]G.AccessorFuncNW [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionSets a accessor variable "Cookies", which you can later read & modify. (use in an scripted entity)
Used onNewerServer.png
Code
AccessorFuncNW( ENT, "Cookies", "NumberOfCookies", 1, FORCE_NUMBER ) --FORCE_NUMBER forces it to be a number.
 
function ENT:Think()
     self:SetNumberOfCookies( self:GetNumberOfCookies() + 1 ) --Add 1 to the number of cookies
     MsgN( Format( "The entity now has %i cookies!", self:GetNumberOfCookies() ) ) --Print it
end
 
--To get number of cookies, use self:GetNumberOfCookies() (or self.Cookies, but that one doesn't always work)
--To set the number of cookies, use self:SetNumberOfCookies()
--It all depends on the third variable of AccessorFuncNW, if you'd change it to e.g. "Pixels" then it'd be GetPixels() and SetPixels()
OutputEvery time the entity thinks: "The entity now has 2 cookies!"


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox