Garry's Mod Wiki

net.WriteInt

net.WriteInt( number integer, number bitCount )

Description

Appends an integer - a whole number - to the current net message. Can be read back with net.ReadInt on the receiving end.

Use net.WriteUInt to send an unsigned number (that you know will never be negative). Use net.WriteFloat for a non-whole number (e.g. 2.25).

Arguments

1 number integer
The integer to be sent.
2 number bitCount
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

Example

Sends the server the client's age.

--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)
Output: Player <name> is 3 years old.

Page Links


Special Pages


Wikis

?

Render Time: 153ms

DB GetPage 24
Generate Html 8
SaveChanges (1) 103
Render Body 0
Render Sidebar 14