You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/dataTypes/Primitives.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,12 @@
7
7
ByteNet provides a large amount of "primitive" types for you to build more complex types that suit your game. Since primitive types don't need any parameters, you can just access them like the following: `ByteNet.<typename>`. For building more complex data structures, go look at the <ahref="../Specials">Specials page.</a>
8
8
9
9
---
10
-
## Supported generic types
10
+
## Supported general types
11
11
-`string`: String
12
12
-`buff`: Buffer
13
13
-`bool`: Boolean
14
+
-`nothing`: Nothing
15
+
-`unknown`: Any type
14
16
---
15
17
## Supported number types
16
18
-`uint8`: Unsigned 8-bit integer
@@ -26,4 +28,5 @@ ByteNet provides a large amount of "primitive" types for you to build more compl
Copy file name to clipboardExpand all lines: docs/api/dataTypes/Specials.md
+52-37Lines changed: 52 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,30 +9,47 @@ Special types are how complex packet types are made. They can take in nearly any
9
9
Special types always take *parameters*. You have to call them: `ByteNet.<type name>(<any primitive type>)`.
10
10
11
11
!!!danger
12
-
### There are drawbacks to using these!
13
-
14
12
- Using these types incurs 1-2 bytes of overhead due to the dynamic nature.
15
13
- They take drastically more time to parse
16
14
- They are heavier on memory usage, as a new closure is created each time. You will never have to worry about this unless you have dozens of packets, though.
17
15
18
16
---
19
17
18
+
## Structs
19
+
Structs let you send structured data in the form of dictionaries. The fields are optimized away, so they don't take any bandwidth. Structs are how you'll be sending most of your data likely: they are the best for organization, and they let you do really interesting things. For example:
Optional types are a cool name for the concept of "This doesn't have to exist". It's good for optional parameters: for example if some invoked function were to fail, you might want to send back a blank copy to indicate that something is wrong.
22
37
23
38
```lua title="packets.luau"
24
-
return {
25
-
myCoolPacket=ByteNet.definePacket({
26
-
structure= {
27
-
-- An "optional" type takes in a parameter.
28
-
-- This can be anything! You can even have optional arrays.
-- Note that even if we don't put the "eachCharacter" field here,
@@ -57,22 +74,22 @@ Arrays are fairly self explanatory. They're just plain old arrays. However, it's
57
74
There is a 2 byte overhead to sending an array in ByteNet. This is because these 2 bytes are an unsigned 16-bit integer, which stores the array length. As a side effect, arrays sent through ByteNet have a max length of **2^16**, which is equal to **65,536**. It's likely that in the future, you will be able to reduce the overhead to 1 byte through configuration, in turn reducing the max length of the array.
-- Important to note that mixed arrays/arrays with holes
74
91
-- shouldn't be sent through.
75
-
myArray= { true, false, true }
92
+
true, false, true
76
93
})
77
94
```
78
95
@@ -84,25 +101,23 @@ Maps are by far the most powerful "special" type in ByteNet. They let you send,
84
101
Like arrays, maps have a 2-byte overhead to store the length of the map. This is done by iterating over the map using <ahref="https://devforum.roblox.com/t/luau-recap-may-2022/1818869">generic iteration</a> and increasing a variable by 1 for every key-value pair. This, once again, means that there is a **2^16** (which equals to **65,536**) cap to the number of elements in the map.
Copy file name to clipboardExpand all lines: docs/api/functions/definePacket.md
+18-20Lines changed: 18 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,22 +12,20 @@ ByteNet's purpose as a library is to provide a way to structure your data, and s
12
12
---
13
13
14
14
## Okay, where do I start?
15
-
I highly recommended storing all of your packets in a single, shared module, and then using a dictionary to access the individual packets. Not only does this make using ByteNet a breeze, it also gives you a better form of typechecking.
16
-
17
-
The keys of your packet determine the ID it gets. The server and the client sharing this key is essential: that's the core of how ByteNet works. Unfortunately, this means you cannot have duplicate contents of packets. **This may change in the future.**
18
-
19
-
Enough of how it works, let's start off with making a basic packet:
15
+
Enough of how it works, let's start off with making a basic packet. We will also need to create a namespace:
@@ -44,32 +42,32 @@ On the client, there is only one, because you can only send data to the server:
44
42
45
43
-`send`
46
44
47
-
These functions *must* obey your structure created in `definePacket`, and if you have strict typing on, an error will be raised if the types do not match.
45
+
Any data passed through these functions *must* obey your structure created in `definePacket`, and if you have strict typing on, an error will be raised if the types do not match.
48
46
49
47
*code examples*
50
48
```lua title="client.luau"
51
49
-- Sending to server
52
-
packets.myPacket:send({
50
+
packets.myPacket.send({
53
51
message="Hello, world!"
54
52
})
55
53
```
56
54
```lua title="server.luau"
57
55
-- Sending to all players
58
-
packets.myPacket:sendToAll({
56
+
packets.myPacket.sendToAll({
59
57
message="Hello, players!"
60
58
})
61
59
62
60
-- Sending to an individual player
63
61
localsomeArbitraryPlayer=Players.You
64
62
65
-
packets.myPacket:sendTo({
63
+
packets.myPacket.sendTo({
66
64
message="Hello, random player!"
67
65
}, someArbitraryPlayer)
68
66
69
67
-- Sending to all except a certain player
70
68
localsomeArbitraryPlayer=Players.You
71
69
72
-
packets.myPacket:sendToAllExcept({
70
+
packets.myPacket.sendToAllExcept({
73
71
message="Hello, everyone except one person!"
74
72
})
75
73
```
@@ -80,12 +78,12 @@ You can use the `listen` method to listen for when a packet is received.
0 commit comments