(Solved) Trying to join match, throwing back closed match error - Godot

Hi everyone! I’m trying to make matches and joining them in my game. The basic idea here is, like clash royale for example, when you click “play” you will automatically be sent to a match.

In my case, I check if there are ongoing matches, if there are not, I create them, otherwise I join. (For testing purposes and get the hang of how this works, this fits me perfectly for now, I know I have a lot to do going forward)

Here is a very basic sample code:

func check_ongoing_matches():
	var min_players = 1
	var max_players = 10
	var limit = 10
	var authoritative = false
	var label = ""
	var query = ""
	var result = await NakamaGlobals.client.list_matches_async(NakamaGlobals.session, min_players, max_players, limit, authoritative, label, query)
	if result.matches == []:
		print("No match, creating")
		create_match()
	for m in result.matches:
		await NakamaGlobals.socket.join_match_async(result.matches[0].match_id)

func create_match():
	var socket_result = await NakamaGlobals.conectar_socket()
	if socket_result == 1:
		_match = await NakamaGlobals.socket.create_match_async()
		get_tree().change_scene_to_file(scene)

It’s hardcoded for now, but it works creating a match. Now the problem comes when trying to join that said match, it throws back:

E 0:00:16:0601 NakamaSocketAdapter.gd:54 @ send(): Condition "ready_state != STATE_OPEN" is true. Returning: FAILED

I believe it means the match has a closed status, right? How then can I create a “open” match? I’m following both Nakama docs and the multiplayer example here, but they don’t talk about this, it’s more of a “invite” only type of joining documented.

Thanks in advance.

Solution here:

It was actuallly an error from Godot itself, telling me it was not connected. I missed connecting to a socket on the second client, so it was giving me that error.
If anyone ever make this same mistake, here is an updated code:

func _ready():
	var socket_result = await NakamaGlobals.conectar_socket()
	if socket_result == 0: #Error
		print(socket_result)

func check_ongoing_matches():
	var min_players = 1
	var max_players = 10
	var limit = 10
	var authoritative = false
	var label = ""
	var query = ""
	var result = await NakamaGlobals.client.list_matches_async(NakamaGlobals.session, min_players, max_players, limit, authoritative, label, query)
	if result.matches == []:
		print("No match, creating")
		create_match()
	else:
		for m in result.matches:
			var match_id : String = str(result.matches[0].match_id)
			var joined_match = await NakamaGlobals.socket.join_match_async(match_id)
			if joined_match.is_exception():
				print("Join Error: %s" % joined_match)
				return
			get_tree().change_scene_to_file(scene)

func create_match():
	_match = await NakamaGlobals.socket.create_match_async()
	get_tree().change_scene_to_file(scene)

It’s missing a lot of bugfixing, I should do a matchmaking pool, etc, but I’m more concerned right now in making it work and then polish it.

I’m gonna note this here:

When searching a match by labels, you have to wait a moment for the labels to update after the match is created. Otherwise you will not find the match. The time you have to wait is configured with label_update_interval_ms

1 Like

Thanks for the note, I actually scraped all that and did something that looks much wiser, using Nakama’s own matchmaking instead of trying to glue together some of my own.