Skip to content

Commit

Permalink
Update function docs
Browse files Browse the repository at this point in the history
:Call now returns a success boolean
  • Loading branch information
Tazmondo committed Jan 3, 2024
1 parent 943c487 commit 9f9bbf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
16 changes: 7 additions & 9 deletions docs/2.0/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Functions allow RemoteFunction-like behavior in Red for calling client -> server.

## SetCallback
## SetCallback <Badge type="tip" text="Server"></Badge>

Sets the function's callback.

Expand All @@ -22,24 +22,22 @@ Function:SetCallback(function(Player, Arg1, Arg2, Arg3)
end)
```

::: danger
If the callback errors the client will never recieve any value and will yield forever. **Doing this is a memory leak!** Do not rely on erroring not sending back values.
:::

## Call
## Call <Badge type="warning" text="Client"></Badge>

Calls the function on the server.

```lua
<A..., R...>(
...A: any -- The arguments to pass to the function.
) -> Future<R...>
) -> Future<boolean, R...> -- A success boolean followed by the returned values
```

A function is called on the client to call the function on the server. This method returns a [Future](https://util.redblox.dev/future) which can be used to await the return values or connect a function to be called when the return values are received.
Functions can only be called from the client. The client must pass valid arguments to the function, and will be given back a [Future](https://util.redblox.dev/future) that completes with the returned values.

It also returns a success boolean, similar to pcall, which is false if the server's callback function errored, and true if it was successful.

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

local Ret1, Ret2, Ret3 = Function:Call(Arg1, Arg2, Arg3):Await()
local Success, Ret1, Ret2, Ret3 = Function:Call(Arg1, Arg2, Arg3):Await()
```
12 changes: 5 additions & 7 deletions docs/guide/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ end)

:::

## Set Callback
## Setting the Callback

A singular callback must be set on the server to allow clients to call the event. This callback is given the arguments and must return the expected return values.
A singular callback must be set on the server to allow clients to call the function. This callback is given the arguments and must return the expected return values. This callback may only be set on the server, attempting to set it on the client will result in an error.

```lua
local Function = require(Path.To.Function)
Expand All @@ -68,16 +68,14 @@ Function:SetCallback(function(Player, Arg1, Arg2, Arg3)
end)
```

::: danger
If the callback errors then the client will never recieve any value and will yield forever. **Doing this is a memory leak!** Do not rely on erroring not sending back values.
:::

## Calling

Functions can only be called from the client. The client must pass valid arguments to the function, and will be given back a [Future](https://util.redblox.dev/future) that completes with the returned values.

It also returns a success boolean, similar to pcall, which is false if the server's callback function errored, and true if it was successful.

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

local Ret1, Ret2, Ret3 = Function:Call("Hello", 1, true):Await()
local Success, Ret1, Ret2, Ret3 = Function:Call("Hello", 1, true):Await()
```

0 comments on commit 9f9bbf8

Please sign in to comment.