I’m making a game that its matches only have 2 players
When the second player joins a match, it should send a message to his opponent so they can both go to the “Accept Match” screen
I’m trying to achieve that by calling
GameManager.socket.send_match_state_async(match_id, op_code, json_message)
method
And hoping to receive the response on _on_received_match_state function, that is also in the GameManager class, but its never triggered!
I already connected this function to the received_match_state event like this: socket.received_match_state.connect(_on_received_match_state)
The match_id is correct, socket is also alive
I’m checking with GameManager.socket.is_connected_to_host(): and its all good but _on_received_match_state is not triggered by my send_match_state_async func!
I’m days stuck at this problem.
Any light for me?
Thanks in advance!
GameManager class (that have socket, client, session logic) :
socket.received_match_state.connect(_on_received_match_state)
func _on_received_match_state(match_state: NakamaRTAPI.MatchData):
var op_code = match_state.op_code
var json_message = JSON.parse_string(match_state.data)
if json_message:
if op_code == 222:
print("Received message:", json_message["message"])
else:
print("Failed to parse JSON message.")
Prematch class, where i call send_match_state_async:
func _on_button_button_up() -> void:
if not GameManager.socket.is_connected_to_host():
print("Socket is not connected. Connecting...")
await GameManager.socket.connect_async(GameManager.session)
var match_id = GameManager.my_match_id
var op_code = 222
var message = "if this is shown, it worked!"
var json_message = JSON.stringify({"message": message})
var result = await GameManager.socket.send_match_state_async(match_id, op_code, json_message)
if result:
print("Message sent successfully!")
else:
print("Failed to send message.")
Important to say that in this part, it prints “Message sent successfully!”
And i have this in the Output log:
Media: