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
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:
- nakama-project-template/match_handler.go at master · heroiclabs/nakama-project-template · GitHub
- nakama-project-template/match_handler.ts at master · heroiclabs/nakama-project-template · GitHub
- game-xoxo-nakama-server/tictactoe_match.lua at main · defold/game-xoxo-nakama-server · GitHub
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.
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: