Turn based game using nakama

hi Nakama developers, I’m working on creating a multiplayer turn-based game in unity using nakama, so far I know everything about authentication, matchmaking and data synchronization but I’m stuck in building the round system, how can I make a system for the players to know it’s their turn??
the game logic will be like this:
we will have two players per session
player1 will perform their action in real time and the other can see it
then they will click a button to change the turn for the next player
in that time they can’t do anything until its their turn
how can I achieve that with nakama ??

Hello @sana2024, the server has to keep track of whose turn it is based on your game logic, and it should send a message to the clients informing them of who’s turn it is when a turn is over, rejecting any operations from the user whose current turn isn’t his.

You can check a full example of a tic-tac-toe implementation here: GitHub - heroiclabs/nakama-project-template: An example project on how to set up and write custom server code in Nakama server., it should help you get started.

Hope this helps.

thanks for the reply,
I thought about a logic myself which is:
I add a button when a player finishes their turn they click it and by that they send the userID of the other player to the server and in the method where we perform the action we check if the userID sent to the server is equal to our own UserID then it means it’s our turn and we can perform the action and after we finish we click the button again to sent the turn for the other player so on and on,

but my problem here is I get back the userID of player inside OnReceiveMatchPresence and this method doesn’t send back the users joined correctly every time nor the OnRecieveMatchPresence sometimes they do and sometimes nothing shows ?? why is that ??

or if you know a better way for doing this please don’t hesitate to guide me

Can you please give some more context - are you using the authoritative engine or client relayed? What SDK are you using on the client?

I’m using client relayed with unity SDK and hosting it on heroic lab for now, plus I have another question , how can I find the host ?? I tried the last solution on client relayed page on Nakama SDK but doesn’t seem to work with my login, I don’t know how to choose which player to start the turn?? so I decided the best way is to make the host the first player, is there any better way?? is there a better way to sort players ??

If you’re using client relayed, we do recommend that you decide who is the host using an alphanumerical sort on the connected presences session Ids and choose the first, like this example: Nakama: Client Relayed Multiplayer | Heroic Labs Documentation.

However it’s hard to understand what your current issue is without more context, what login do you mean? is it an authentication issue with the clients? Can you post some server logs or errors?

Can you share how you’re handling the OnReceiveMatchPresence hook?

What do you mean with you’re hosting it on Heroic Lab, you’re using our Heroic Cloud?