Revision Difference
net.WriteInt#562840
<function name="WriteInt" parent="net" type="libraryfunc">
<description>
Appends a signed integer - a whole number, positive/negative - 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 |
| 11 | -1,024 | 1,023 |
| 12 | -2,048 | 2,047 |
| 13 | -4,096 | 4,095 |
| 14 | -8,192 | 8,191 |
| 15 | -16,384 | 16,383 |
| 16 | -32,768 | 32,767 |
| 17 | -65,536 | 65,535 |
| 18 | -131,072 | 131,071 |
| 19 | -262,144 | 262,143 |
| 20 | -524,288 | 524,287 |
| 21 | -1,048,576 | 1,048,575 |
| 22 | -2,097,152 | 2,097,151 |
| 23 | -4,194,304 | 4,194,303 |
| 24 | -8,388,608 | 8,388,607 |
| 25 | -16,777,216 | 16,777,215 |
| 26 | -33,554,432 | 33,554,431 |
| 27 | -67,108,864 | 67,108,863 |
| 28 | -134,217,728 | 134,217,727 |
| 29 | -268,435,456 | 268,435,455 |
| 30 | -536,870,912 | 536,870,911 |
| 31 | -1,073,741,824 | 1,073,741,823 |
| 32 | -2,147,483,648 | 2,147,483,647 |
</arg>
</args>
</function>
<example>
<description>Sends the server the client's age.</description>
<code>
-- Client
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()
-- Server
util.AddNetworkString( "SendAge" )
net.Receive( "SendAge", function( 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 )
</code>
<output>Player `<name>` is 3 years old.</output>
</example>