Garry's Mod Wiki

Revision Difference

Entity:NetworkVar#514648

<function name="NetworkVar" parent="Entity" type="classfunc">⤶ <description>⤶ Creates a network variable on the entity and adds Set/Get functions for it. This function should only be called in <page>ENTITY:SetupDataTables</page>.⤶ ⤶ <warning>Make sure to not call the SetDT* and your custom set methods on the client realm unless you know exactly what you are doing.</warning>⤶ </description>⤶ <realm>Shared</realm>⤶ <args>⤶ <arg name="type" type="string">Supported choices:&#xA;&#xA;* &quot;String&quot;&#xA;* &quot;Bool&quot;&#xA;* &quot;Float&quot;&#xA;* &quot;Int&quot; (32-bit signed integer)&#xA;* &quot;Vector&quot;&#xA;* &quot;Angle&quot;&#xA;* &quot;Entity&quot;</arg>⤶ <arg name="slot" type="number">Each network var has to have a unique slot. The slot is per type - so you can have an int in slot 0, a bool in slot 0 and a float in slot 0 etc. but you can&#x27;t have two ints in slot 0 instead you would do a int in slot 0 and another int in slot 1. &amp;amp;lt;br&amp;amp;gt;&#xA;The max slots right now are 64 - so you should pick a number between 0 and 63. An exception to this is strings which has a max slots of 4.</arg>⤶ <arg name="name" type="string">The name will affect how you access it. If you call it &quot;Foo&quot; you would add two new functions on your entity - SetFoo and GetFoo. So be careful that what you call it won&#x27;t collide with any existing functions (don&#x27;t call it &quot;Pos&quot; for example).</arg>⤶ <arg name="extended" type="table" default="nil">A table of extended information. &#xA;&#xA;**KeyName**&#xA;&#xA;If the table contains a &quot;KeyName&quot; key the value can be set using &lt;page&gt;Entity:SetKeyValue&lt;/page&gt;. This is useful if you&#x27;re making an entity that you want to be loaded in a map. The sky entity uses this.&#xA;&#xA;**Edit**&#xA;&#xA;The edit key lets you mark this variable as editable. See &lt;page&gt;Editable Entities&lt;/page&gt; for more information.</arg>⤶ </args>⤶ </function>⤶ ⤶ <example>⤶ <description>Setting up data tables</description>⤶ <code>⤶ function ENT:SetupDataTables()⤶ ⤶ self:NetworkVar( "Float", 0, "Amount" )⤶ self:NetworkVar( "Vector", 0, "StartPos" )⤶ self:NetworkVar( "Vector", 1, "EndPos" )⤶ ⤶ end⤶ ⤶ -- Code...⤶ ⤶ -- Setting values on the entity⤶ self:SetStartPos( Vector( 1, 0, 0 ) )⤶ self:SetAmount( 100 )⤶ ⤶ -- Code...⤶ ⤶ -- Getting values⤶ local startpos = self:GetStartPos()⤶ </code>⤶ ⤶ </example>