File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ title: Remote Procedure Calls (RPC)
88You can use the ` @rpc ` decorators to mark behavior functions as remote procedures. RPC decorated functions ** must** have
99all 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
1316Annotate 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
2427export 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```
You can’t perform that action at this time.
0 commit comments