Some Godot questions

Hello, I’m a software engineer (primarily C++) and I’ve just started using Godot, Nakama & lua. I’m loving it so far, it’s going really well except a few things I have questions about and can’t seem to find the answer online:

  1. How do I set the token expiry time? It seems really short currently and I don’t want to run a loop or check expired (and re-authenticate if so) every time I make a server call.

  2. I can’t seem to ever get multiple matches happening at the same time. If I create one match then another, nakama.match_list() seems to only return one of them. Is there something I’m missing?

  3. My match state doesn’t seem to be returning via match_init() (or existing at all, ever). What am I doing wrong in this case?

Here is my rpc module (related to question 2, the logger_info call is just to see what I’m getting back)

local nakama = require("nakama")

local function create_match(_, payload)
	return nakama.match_create("cube_draft", {initial_state = payload})
end

local function get_match_list(_, _)
	local matches = nakama.match_list()
	for _, m in ipairs(matches) do
		nakama.logger_info(string.format("ID: %q, Name: %q", m.match_id, m.label))
	end
	return nakama.json_encode(nakama.match_list())
end

nakama.register_rpc(create_match, "create_match")
nakama.register_rpc(get_match_list, "get_match_list")

And here is a snippet from my match module (related to question 3)

local nakama = require("nakama")

local cube_draft = {}

-- These should match the keys in N_Messages
local KEY_MATCH_NAME = "match_name"
local KEY_MATCH_SEED = "match_seed"

function cube_draft.match_init(context, params)
	local json = nakama.json_decode(params.initial_state)
	local state = {
		has_started = false,

		seed = json[KEY_MATCH_SEED],

		presences = {},
		player_indices = {},
		picks = {},
		review_complete = {}
	}
	local tick_rate = 4
	local label = json[KEY_MATCH_NAME]

	return state, tick_rate, label
end

Hi @Shikadi welcome :wave:

Thanks for the kind words about the tech. We appreciate it and any feedback you have let me know as we’ve always got new features and improvements we want to make to ensure the server is easier to use and more flexible to different game projects.

I’ll answer each of your questions inline.

How do I set the token expiry time? It seems really short currently and I don’t want to run a loop or check expired (and re-authenticate if so) every time I make a server call.

This comes up a lot so we have to improve our documentation around it. We also have improvements planned to handle automatic token refresh in our client SDKs. In the meantime (and what we’d usually recommend) is to set the session lifetime on the token to 3-4x of the expected average play session length. Have a look at the “–session.token_expiry_sec ” option in the server which can be set at server start and also in the YML file.

https://heroiclabs.com/docs/install-configuration/#session

I can’t seem to ever get multiple matches happening at the same time. If I create one match then another, nakama.match_list() seems to only return one of them. Is there something I’m missing?

You should get back the matches you look for but you don’t pass any arguments into the match listings:

https://heroiclabs.com/docs/runtime-code-function-reference/#match

Have a look at the inputs to match_list in the function reference.

My match state doesn’t seem to be returning via match_init() (or existing at all, ever). What am I doing wrong in this case?

Have you implemented all the lifecycle functions that are needed for a match handler?

1 Like

Thank you very much for the reply!

For some reason I assumed the default matches returned would be all rather than one, should have looked at the documentation properly, thanks for that!

I realised the state isn’t inherently exposed to Godot, I had to use the dispatcher to send data out to the client.

1 Like