I have made a lot of progress, thanks to everyone for the help.
use op_code
field to distinguish the events you send between the players
@uncle_Night thanks for this advice. Sounds like op_code is kind of similar to message_id in Defold.
On to my current position.
I am now able to use the matchmaker to, well, matchmake! I get the callback successfully and am then able to actually join/create the match. My issue now is I am unable to get the format of the data right for a match data message.
I know my socket is right, I know I have the right match id and that I am using op_code correctly. I know this because I can send a match data message with no data:
My code (with no data)
local match_data = {
match_data_send = {
match_id = match.match.match_id,
op_code = 1337,
data = {}
}
}
pprint(match_data)
print("sending match data...")
nakama.socket_send(socket, match_data, function(message)
print("data send callback")
pprint(message)
end)
Callback successful
If I try to send a regular Lua table:
data = {some_var = "some_value"}
My on_disconnect callback is triggered and I see the following in the Docker log for Nakama (Received malformed payload):
{"level":"warn","ts":"2020-07-24T08:26:47.251Z","msg":"Received malformed payload","uid":"8a99c291-36b9-4121-994f-4d6a0c94764c","sid":"723c7437-daca-47a4-b295-2c331c28be75","data":"eyJtYXRjaF9kYXRhX3NlbmQiOnsibWF0Y2hfaWQiOiJlNWE2Njg1ZS0wN2JlLTRjMWMtODM4ZC0zODZlMTEzZTg4NWUuIiwib3BfY29kZSI6MTMzNywiZGF0YSI6eyJzb21lX3ZhciI6InNvbWVfdmFsdWUifX0sImNpZCI6IjMifQ=="}
{"level":"info","ts":"2020-07-24T08:26:47.251Z","msg":"Closed client connection","uid":"8a99c291-36b9-4121-994f-4d6a0c94764c","sid":"723c7437-daca-47a4-b295-2c331c28be75"}
I know from the docs that there is a specific format required, like JSON. So I try to encode a table of values using CJSON:
data = cjson.encode({move = {dir = "left", steps = 4}})
If I just print the encode itself I get:
{"move":{"dir":"left", "steps":4}}
This exactly matches the documentation. But if I pprint the table I am passing into the socket_send, the data table is wrapped in quotation marks to make it a string. I assume this is the reason for the payload being malformed:
"{"move":{"dir":"left", "steps":4}}"
Am I on the right path? What am I missing? I just can’t figure out how to format the data properly.