Server deciding players' turn at the start of the match

For a game like tic tac toe , when two players are connected, how to randomly assign each player either “X” or “O” from server side (preferably in lua). The game is made with godot but I believe the server code will be same for any other game engine.

Hi @mdee5 :wave:

That’s a great question. We actually have a TicTacToe demo with a full server implementation that you can look at in Go, TypeScript, and/or Lua:

In principle what you do is either make the match creator have the O or X; alternatively you sort the list of match presences alphanumerically so that all game clients within the match can deterministically know who goes first (and that player will be defined to use O or X).

Hope that helps.

1 Like

Can we send message to single user only from the server side?
dispatcher.broadcast_message(*)
sends message to every joined users ( I guess).

@mdee5 Yes you can of course broadcast messages to a single user, group of users, or all users within the multiplayer match. You can see an example of that in the codebase links I shared here: