Revision Difference
net.WriteInt#516013
<function name="WriteInt" parent="net" type="libraryfunc">
<description>
Appends an integer - a whole number - to the current net message. Can be read back with <page>net.ReadInt</page> on the receiving end.
Use <page>net.WriteUInt</page> to send an unsigned number (that you know will never be negative). Use <page>net.WriteFloat</page> for a non-whole number (e.g. 2.25).
</description>
<realm>Shared</realm>
<args>
<arg name="integer" type="number">The integer to be sent.</arg>
<arg name="bitCount" type="number">The amount of bits the number consists of. This must be 32 or less.

If you are unsure what to set, just set it to 32.



+Consult the table below to determine the bit count you need.| Bit Count | Minimum value | Maximum value |
-------------------------------------------------------------|------------|----------------|---------------|
| 3 | -4 | 3 |
| 4 | -8 | 7 |
| 5 | -16 | 15 |
| 6 | -32 | 31 |
| 7 | -64 | 63 |
| 8 | -128 | 127 |
| 9 | -256 | 255 |
| 10 | -512 | 511 |
| 11 | -1024 | 1023 |
| 12 | -2048 | 2047 |
| 13 | -4096 | 4095 |
| 14 | -8192 | 8191 |
| 15 | -16384 | 16383 |
| 16 | -32768 | 32767 |
| 17 | -65536 | 65535 |
| 18 | -131072 | 131071 |
| 19 | -262144 | 262143 |
| 20 | -524288 | 524287 |
| 21 | -1048576 | 1048575 |
| 22 | -2097152 | 2097151 |
| 23 | -4194304 | 4194303 |
| 24 | -8388608 | 8388607 |
| 25 | -16777216 | 16777215 |
| 26 | -33554432 | 33554431 |
| 27 | -67108864 | 67108863 |
| 28 | -134217728 | 134217727 |
| 29 | -268435456 | 268435455 |
| 30 | -536870912 | 536870911 |
| 31 | -1073741824 | 1073741823 |
| 32 | -2147483648 | 2147483647 |</arg>
</args>
</function>
<example>
<description>Sends the server the client's age.</description>
<code>
--Client
function SendAge()
net.Start("SendAge")
net.WriteInt(3, 3) -- Only 2 bits are needed to store the number '3', but we add one because of the rule.
net.SendToServer()
end
--Server
util.AddNetworkString("SendAge")
local function GetAge(len, ply)
local age = net.ReadInt(3) -- use the same number of bits that were written
print("Player " .. ply:Nick() .. " is " .. age .. " years old."
end
net.Receive("SendAge", GetAge)
</code>
<output>Player &lt;name&gt; is 3 years old.</output>
</example>