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

**URL:** <https://forum.heroiclabs.com/t/solved-trying-to-join-match-throwing-back-closed-match-error-godot/3811>\
**Category:** Local Setup\
**Tags:** matches\
**Created:** [April 19, 2023, 12:26pm UTC](https://forum.heroiclabs.com/t/solved-trying-to-join-match-throwing-back-closed-match-error-godot/3811 "2023-04-19T12:26:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luiscesjr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/luiscesjr/32/1155_2.png) [@luiscesjr](https://forum.heroiclabs.com/u/luiscesjr)\
**Post date:** [April 19, 2023, 12:26pm UTC](https://forum.heroiclabs.com/t/solved-trying-to-join-match-throwing-back-closed-match-error-godot/3811/1 "2023-04-19T12:26:00Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dela](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/dela/32/1489_2.png) [@dela](https://forum.heroiclabs.com/u/dela)\
**Post date:** [April 26, 2023, 12:14pm UTC](https://forum.heroiclabs.com/t/solved-trying-to-join-match-throwing-back-closed-match-error-godot/3811/2 "2023-04-26T12:14:42Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![luiscesjr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/luiscesjr/32/1155_2.png) [@luiscesjr](https://forum.heroiclabs.com/u/luiscesjr)\
**Post date:** [April 26, 2023, 12:55pm UTC](https://forum.heroiclabs.com/t/solved-trying-to-join-match-throwing-back-closed-match-error-godot/3811/3 "2023-04-26T12:55:18Z")

</div>

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.
