Closed dlannan-kakutai closed 1 year ago
local data = nk.json_decode(payload[1])
Why do you expect a payload to be a list? It is only what you send in your RPC call - meaning, an entire JSON object.
Also, the payload is the second argument to any RPC function, you're not supposed to fetch it from the context
, it's documented with an example here
Try this instead:
local function my_test_rpc(context, payload)
local data = nk.json_decode(payload)
print("data.name = ", data.name)
end
nk.register_rpc(my_test_rpc, "test_rpc")
Oh. soz. Thanks for the response. Im an idiot.
Seems like this is solved? Closing.
After referring to a number of examples and documents here: https://heroiclabs.com/docs/runtime-code-basics/#rpc-example https://heroiclabs.com/docs/gameplay-multiplayer-server-multiplayer/#manually And api references, I was going a little crazy trying to determine why my payload was always and empty string. I havent tracked it in the code (nor am I going to spend time doing so right now) but there is no need to use it. All the payload and information in lua modules can be extracted from the first param - context. Heres a quick example for people having problems getting rpc to work:
To call it from the client I use something like this:
If you have any problems please let me know. The above is untested, but its very close to what Im using.