Nakama official client

Good question! The code snippets in the docs only show Unity examples. Post on the Nakama forum as well and ask!

@Lex The IAP validation stuff was moved to Lua utils a while back and that page should not be reachable in our main documentation (I think it’s left behind because of a CDN). We are working to bring back the official API for it though with new improvements to handle subscription callbacks with Battle Pass style purchases. The new IAP system with support AppStore, Play Store, and AppGallery (from Huawei).

In the meantime have a look at this code for what you need:

3 Likes

Thanks for the help!
Yes I figured it out and implemented it correctly.

By the way, I had the add the query parameter unwrap=1 when calling RPC functions, otherwise it wouldn’t work.

@novabyte Do you have any example of working Nakama+Defold Google login?
I can’t make it work, because I can’t get the Oauth token from the Google Play Game Services Defold SDK.
Is there any other way to get the Google Oauth token? (I posted a thread Google Play Game service: access token for Nakama but can’t get help on this).

1 Like

I saw the PR for this here: https://github.com/heroiclabs/nakama-defold/pull/27

I added a comment about this since the PR modified generated code which would get overwritten the next time the API was generated.

i try to send message, but nothing happen:

function M.sendMessage()
	nakama.sync(function()
		local data = json.encode({
			row = 11,
			col = 22,
		})
		data=base64.encode(data)
		local op_code = 1
		local result = nakama_socket.match_data_send(socket, matchID, op_code, data)
		print("sended")
		if result.error then
			print(result.error.message)
			pprint(result)
		else
			print("ok!!!")
		end
	end)
end

“sended” - is not print. Please help! What i do wrong?

Which Nakama version are you using? The fact that you do not see your print indicates that something crashed inside the coroutine. But there console should show the error. You can try sending it without a coroutine (ie not inside nakama.sync)

Also, they should be no need to base 64 encode the data. It is handled automatically:

I used 3.0.3, then I saw on github that I needed to use the master. Yes indeed b64 is no longer needed.
if i send without “sync” i have error:

ERROR:SCRIPT: nakama/util/async.lua:19: assertion failed!
stack traceback:
  [C]:-1: in function assert
  nakama/util/async.lua:19: in function match_data_send
  main/multiplayer.lua:122: in function sendMessage
  main/main.gui_script:31: in function callback
  druid/event.lua:90: in function trigger
  druid/base/button.lua:88: in function on_button_click
  druid/base/button.lua:159: in function on_input
  druid/system/druid_instance.lua:183: in function process_input
  druid/system/druid_instance.lua:359: in function <druid/system/druid_instance.lua:354>

Did you provide a callback function? Required if you are not running from a coroutine.

i realy not specify callback. Thanks britzl! I write but something wrong because i dont recive result:

		player_socket.match_data_send(matchID, op_code, data,nil,nil,
	function() 
		print("player_socket.match_data_send")
		pprint(result)
	end)

Can you please provide a minimal example where I can test this?

1 Like

i find solution

Ah, good to hear!

1 Like

NIce to hear!
Is it something you could share with the other forum users finding this thread?

1 Like

i just ignored that callback dont sent. We can listen message when create socket connection

		-- Called by Nakama when the game state has changed.
	-- We parse the data and send it to the game.
	player_socket.on_match_data(function(message)
		pprint({ on_match_data = {message} })
		handle_match_data(message.match_data)
1 Like

I noticed there is no “result” variable in the function() call, which I guess explains why the result prints nil?

I would have expected it to be something like this (but I haven’t used Nakama for a while):

 function(result)
3 Likes

Correct, the result is returned in the callback function:

2 Likes

I have problems with Yandex. Their platform does not pass ports. Is it possible to somehow do without ports in nakama?
upd: i configured nakama to port 443.

Nakama time again!

I have a project where everything works great. I’m now trying to implement on_matchmaker_matched() and I get an error.

This is the client code, which returns the token correctly:

	socket.on_matchmaker_matched(function(message)
		pprint("Received:", message);
		local match_id = nil
		local token = message.matchmaker_matched.token
		local metadata = nil
		local callback = nil
		print(match_id, token, metadata, callback)
		local match_join_result = socket.match_join(match_id, token, metadata, callback)
		on_joined_match(match_join_result)
	end)

When it comes to the socket.match_join() line it throws this error:

ERROR:SCRIPT: nakama/util/async.lua:19: assertion failed!
stack traceback:
  [C]:-1: in function assert
  nakama/util/async.lua:19: in function match_join

Joining with a match_id works fine, so I’m wondering if there is an issue in the part that uses a token to join a match.

I noticed the Tictactoe example also tries to do this, but it looks outdated since it’s using realtime, which I believe has been deprecated, to joint the match:

local result = realtime.match_join(socket, match_id, token)
if result.match then
	print("Match joined!")
end

Has anyone been able to use the latest version of Nakama with Defold and successfully used the Matchmaker? If not, any other thoughts on what might be up here?

Update:

The online demo doesn’t seem to connect. After downloading the project, the client gets this error from the server (at xoxo-prod1.eu-west1-a.nakamacloud.io):

DEBUG:SCRIPT: 
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>502 Server Error</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Server Error</h1>
<h2>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.</h2>
<h2></h2>
</body></html>

DEBUG:SCRIPT: Unable to login

Update 2:

The assertion above was because the callback is required. This code works:

	socket.on_matchmaker_matched(function(message)
		pprint("Received:", message);
		local match_id = nil
		local token = message.matchmaker_matched.token
		local metadata = nil
		local callback = match_join_result
		local match_join_result = socket.match_join(match_id, token, metadata, callback)
	end)

Ok, so it works now?

Yes! My project does, adding the missing callback did the trick.

The Defold XOXO test game still doesn’t seem to connect for some reason.

1 Like