Skip to content

Commit d783a48

Browse files
committed
add rpc context to docs
1 parent 0fe6a30 commit d783a48

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

docs/guide/rpc.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ title: Remote Procedure Calls (RPC)
88
You can use the `@rpc` decorators to mark behavior functions as remote procedures. RPC decorated functions **must** have
99
all arguments (and in some cases return types) serializable to `JsonValue`.
1010

11+
You can access information about the RPC call by adding `ctx = rpc.DEFAULT_CONTEXT` as the final argument in an `@rpc`
12+
annotated function.
13+
1114
## Server
1215

1316
Annotate a function with `@rpc.server` to mark it as server-only. Regardless of where this function is called, it will
@@ -23,15 +26,14 @@ import { Behavior, rpc } from "@dreamlab/engine";
2326

2427
export default class RpcBehavior extends Behavior {
2528
@rpc.server()
26-
async hello(from: string): Promise<void> {
29+
async hello(ctx = rpc.DEFAULT_CONTEXT): Promise<void> {
2730
// check server logs to see these messages
28-
console.log("hello from: " + target);
31+
console.log("hello from: " + ctx.from);
2932
}
3033

3134
onInitialize(): void {
32-
// get our own network id and run rpc function
33-
const self = this.game.network.self;
34-
this.hello(self);
35+
// run rpc function when this behavior initializes
36+
this.hello();
3537
}
3638
}
3739
```

0 commit comments

Comments
 (0)