Skip to content

Commit

Permalink
Update SharedSignalEvent docs to specify that it returns a disconnect…
Browse files Browse the repository at this point in the history
… function
  • Loading branch information
Tazmondo committed Jan 3, 2024
1 parent 2168463 commit fb7f6bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docs/2.0/SharedSignalEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ SharedEvents are built on the same backend networking as regular events. However
Unlike [SharedEvents](SharedEvent), SharedSignalEvents may have any number of listeners set.

## OnServer <Badge type="tip" text="Server"></Badge>
Sets the server callback.
Adds a server callback, returning a disconnect function.
```lua
<T...>(
Listener: (Player: Player, T...) -> () -- The listener to register
) -> ()
) -> (() -> ()) -- Disconnect function
```
This method sets the server callback. Errors if called from the client.
This method adds a server callback, returning a disconnect function. Errors if called from the client.
```lua
MyEvent:OnServer(function(Player, Argument)
print(Player, Argument)
end)
```

## OnClient <Badge type="warning" text="Client"></Badge>
Sets the client callback.
Adds a client callback, returning a disconnect function.
```lua
<T...>(
Listener: (T...) -> () -- The listener to register
) -> ()
) -> (() -> ()) -- Disconnect function
```
This method sets the client callback. Errors if called from the server.
This method adds a client callback, returning a disconnect function. Errors if called from the server.
```lua
MyEvent:OnClient(function(Argument)
print(Argument)
Expand Down
12 changes: 9 additions & 3 deletions docs/guide/events/sharedevent.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Shared Events are simply a different way of using Events. They both use the same

They have the major benefit of not needing to explicitly call `Event:Server` or `Event:Client` before being usable. Both your server and client code can simply require them and start using them.

There are two types of Shared Events: The default `SharedEvent`, and the Signal-based `SharedSignalEvent`. By default, Shared Events only allow you to set one callback function, but Shared Signal Events allow you to have any number of callbacks.
There are two types of Shared Events: The default [SharedEvent](/2.0/SharedEvent), and the Signal-based [SharedSignalEvent](/2.0/SharedSignalEvent). By default, Shared Events only allow you to set one callback function, but Shared Signal Events allow you to have any number of callbacks.

This is marginally worse for performance, as it has to use a Signal to fire the callbacks - hence why it is not the default.

Expand Down Expand Up @@ -72,9 +72,12 @@ end)
Events.PayloadSignalEvent:OnClient(function(number)
print("Callback 1", number)
end)
Events.PayloadSignalEvent:OnClient(function(number)

local DisconnectFunction = Events.PayloadSignalEvent:OnClient(function(number)
print("Callback 2", number)
end)

DisconnectFunction() -- Disconnects the 2nd callback.
```

### Server
Expand All @@ -92,9 +95,12 @@ end)
Events.PayloadSignalEvent:OnServer(function(Player, number)
print("Callback 1 from", Player, number)
end)
Events.PayloadSignalEvent:OnServer(function(Player, number)

local DisconnectFunction = Events.PayloadSignalEvent:OnServer(function(Player, number)
print("Callback 2 from", Player, number)
end)

DisconnectFunction() -- Disconnects the 2nd callback.
```

## Firing Events
Expand Down

0 comments on commit fb7f6bf

Please sign in to comment.