I’m new to both Nakama and Defold, and I’m playing with Nakama in a very simple project just to evaluate it. I’m using Docker with Nakama and have it all set up.
The first thing I tried to do after getting authentication working is join a chat room and send a chat message.
The official defold guide and the github repo maintained by @britzl do not agree on how to send a chat message, and they are both wrong. I’m trying to understand why - is it because no one uses nakama with defold and so no one tests the code in the first place, or was nakama recently overhauled and so everything may have changed slightly? If I understand the history of what may have happened I can better predict where things might break, but the very first thing I try having wrong documentation in multiple places is not very beginner friendly.
Method 1 steps to reproduce the problem:
Go here:
and change the dropdowns at the top of the page to “Defold” and “Lua”
Scroll down to the Rooms section and you will see this code:
local roomname = "MarvelMovieFans"
local persistence = true
local hidden = false
local channel = socket.channel_join(roomname, socket.CHANNELTYPE_ROOM, persistence, hidden)
print("Now connected to channel id: " .. channel.id);
The problem is you will be using the channel.id here to send a chat message later, and this syntax is incorrect. socket.channel_join
returns a table with channel as a nested table inside it, so the correct syntax is:
print("Now connected to channel id: " .. channel.channel.id);
Then sending a chat message using code further down on the same page will work once you have the right channel_id.
Method 2 steps to reproduce the problem:
Go here:
Scroll down to the Socket section and you will see this code:
-- send channel join message
local channel_id = "pineapple-pizza-lovers-room"
local result = socket.channel_join(socket, 1, channel_id, false, false)
-- send channel messages
local result = socket.channel_message_send(channel_id, "Pineapple doesn't belong on a pizza!")
This would be a lot more intuitive if it worked, but the channel_id
is wrong again. The actual channel_id is something like 2...pineapple-pizza-lovers-room
even though the channel_id was created as pineappled-pizza-lovers-room
, it seems to require the user_id (relative to the chat room? I’m not sure) with a weird triple dots prefix to the original channel id for this to work, which is the same weird channel_id
returned by channel.channel.id
from method 1.