Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Nov 30, 2023
1 parent 4a740da commit 2bbba77
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.6.0

- Add support for UnreliableRemoteEvents (using `Knit.CreateUnreliableSignal()` on server)
- Update dependencies

## 1.5.3

- Fix incorrect RunService call
Expand Down
2 changes: 1 addition & 1 deletion docs/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Installing Knit is very simple. Just drop the module into ReplicatedStorage. Kni

**Rojo/Wally workflow:**

- Add Knit to your `wally.toml` dependency list (e.g. `Knit = "sleitnick/knit@^1.5"`)
- Add Knit to your `wally.toml` dependency list (e.g. `Knit = "sleitnick/knit@^1.6"`)
- Require Knit like any other module grabbed from Wally

:::note Wally
Expand Down
25 changes: 22 additions & 3 deletions docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ PointsService:GetPoints():andThen(function(points)
end)
```

### Signals (Server-to-Client)
### Events (Server-to-Client)

We should also create a signal that we can fire events for the clients when their points change. We can use `Knit:CreateSignal()` to indicate we want a signal created for the service.
We can use remote signals to fire events from the server to the clients. Continuing with the previous PointsService example, let's create a signal that fires when a client's points change. We can use `Knit:CreateSignal()` to indicate we want a signal created for the service.

```lua
local PointsService = Knit.CreateService {
Expand Down Expand Up @@ -214,7 +214,7 @@ PointsService.PointsChanged:Connect(function(points)
end)
```

### Signals (Client-to-Server)
### Events (Client-to-Server)

Signal events can also be fired from the client. This is useful when the client needs to give the server information, but doesn't care about any response from the server. For instance, maybe the client wants to tell the PointsService that it wants some points. This is an odd use-case, but let's just roll with it.

Expand Down Expand Up @@ -264,6 +264,25 @@ PointsService.GiveMePoints:Fire()
See the [ClientRemoteSignal](https://sleitnick.github.io/RbxUtil/api/ClientRemoteSignal) documentation for more info on how to use the ClientRemoteSignal object.
:::

### Unreliable Events

Knit also supports [UnreliableRemoteEvents](https://create.roblox.com/docs/reference/engine/classes/UnreliableRemoteEvent), which is a special version of RemoteEvent. UnreliableRemoteEvents are, as the name suggests, unreliable. When an event is fired on an UnreliableRemoteEvent, the order and delivery of the event is not guaranteed. The listener of the event may receive the events out of order, or possibly not at all.

Having unreliable events is useful in scenarios where the data being sent is not crucial to game state. For example, setting the tilt rotation of each avatar's head: if some packets are dropped, this won't affect actual gameplay. The benefit is that unreliable events take up less network bandwidth.

To create an unreliable event, use `Knit.CreateUnreliableSignal()` within the client table of a service:

```lua
local MyService = Knit.CreateService {
Name = "MyService",
Client = {
PlayEffect = Knit.CreateUnreliableSignal(),
},
}
```

Using the unreliable signal is the same as normal ones (see the two sections above on events).

### Properties

It is often useful to replicate data to all or individual players. Instead of creating methods and signals to communicate this data, RemoteProperties
Expand Down
5 changes: 0 additions & 5 deletions foreman.toml

This file was deleted.

18 changes: 17 additions & 1 deletion src/KnitServer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,23 @@ function KnitServer.CreateSignal()
end

--[=[
DOCS TODO
@return UNRELIABLE_SIGNAL_MARKER
Returns a marker that will transform the current key into
an unreliable RemoteSignal once the service is created. Should
only be called within the Client table of a service.
See [RemoteSignal](https://sleitnick.github.io/RbxUtil/api/RemoteSignal)
documentation for more info.
:::info Unreliable Events
Internally, this uses UnreliableRemoteEvents, which allows for
network communication that is unreliable and unordered. This is
useful for events that are not crucial for gameplay, since the
delivery of the events may occur out of order or not at all.
See the documentation for [UnreliableRemoteEvents](https://create.roblox.com/docs/reference/engine/classes/UnreliableRemoteEvent)
for more info.
]=]
function KnitServer.CreateUnreliableSignal()
return UNRELIABLE_SIGNAL_MARKER
Expand Down

0 comments on commit 2bbba77

Please sign in to comment.