Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nezuo committed Nov 24, 2024
1 parent 7c6dc9a commit 769b1e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
12 changes: 12 additions & 0 deletions docs/config/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const example = `event MyEvent = {
bar: u8,
},
}`

const dataExample = `event MyEvent = {
from: Server,
type: Reliable,
call: ManyAsync,
data: (boolean, u32, string)
}`
</script>

# Events
Expand Down Expand Up @@ -56,3 +63,8 @@ Use synchronous events with extreme caution.
### `data`

This field determines the data that is sent with the event. It can be any [Zap type](./types.md).

- If the event does not require any data, the `data` field should be excluded.
- You can pass multiple arguments to the event by using a tuple:

<CodeBlock :code="dataExample" />
16 changes: 16 additions & 0 deletions docs/config/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const example = `funct Test = {
},
rets: enum { Success, Fail }
}`

const tupleExample = `funct Tuples = {
call: Async,
args: (boolean, u8),
rets: (boolean, string)
}`
</script>

# Functions
Expand Down Expand Up @@ -41,6 +47,16 @@ Use synchronous functions with extreme caution.

This field determines the data that is sent to the server. It can be any [Zap type](./types.md).

- If the client doesn't send any data, the `args` field should be excluded.
- You can pass multiple arguments to the function by using a tuple:

<CodeBlock :code="tupleExample" />

### `rets`

This field determines the data that is sent back to the client from the server. It can be any [Zap type](./types.md).

- If the server doesn't return any data, the `rets` field should be excluded.
- The function can return multiple values by using a tuple:

<CodeBlock :code="tupleExample" />
14 changes: 5 additions & 9 deletions docs/usage/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ event AnotherEvent = {
from: Client,
type: Reliable,
call: SingleAsync,
data: struct {
baz: boolean,
},
data: (boolean, u8)
}`
</script>

Expand Down Expand Up @@ -50,7 +48,7 @@ If your event's [call field](../config/events.md#call) is `SingleAsync` or `Sing
local Zap = require(Path.To.Zap)

-- only server listeners are given the player argument
Zap.AnotherEvent.SetCallback(function(Player, Data)
Zap.AnotherEvent.SetCallback(function(Player, Bool, Number)
-- Do something with the player and data
end)
```
Expand Down Expand Up @@ -81,14 +79,12 @@ Use `Sync` events only when performance is critical.

## Firing From the Client

The client only has a single function for firing events, `Fire`. This function takes the event's data as its only argument.
The client only has a single function for firing events, `Fire`. This function takes the event's data as it arguments.

```lua
local Zap = require(Path.To.Zap)

Zap.AnotherEvent.Fire({
baz = true,
})
Zap.AnotherEvent.Fire(true, 32)
```

## Firing From the Server
Expand Down Expand Up @@ -116,7 +112,7 @@ Zap.MyEvent.Fire(Player, {

### FireAll

The `FireAll` function takes the event's data as its only argument. It will fire the event to all players.
The `FireAll` function takes the event's data as its arguments. It will fire the event to all players.

```lua
local Zap = require(Path.To.Zap)
Expand Down

0 comments on commit 769b1e8

Please sign in to comment.