Hey all,
I couldn’t seem to find an answer to this via googling (which really surprised me since I’m sure this must have been asked / covered before). I’m currently making my first networked game (Unity front-end, Nakama back-end). I’ve been developing it with multiplayer first since my understanding is that adding networking to an existing project is a lot more work (makes sense to me).
It’s a digital board game / turn based strategy game so minimal latency requirements but reliable turn synchronisation and state consistency. There are a lot of unique actions that players can take (each player has a deck of actions, there are universal actions such as moving, items etc.) and a lot of procedural board state updates which all need to be validated authoritatively by the server. I’ve prototyped this system using mostly pure Lua modules and just have a main.lua file for general RPCs and a game.lua file which is my match handler.
Anyway, I’m now at the point where I’m now also considering how the offline gameplay will work. Since all of the gameplay logic is happening on the server and the client just reconstructs the state as it’s instructed I’m wondering what the best way to add the gameplay logic back into the offline mode would be. As far as I can see there are 3 paths forward (although possibly more I haven’t considered)
1 - Rewrite the gameplay logic in Unity. This doesn’t seem like a good solution to me since there could end up being bugs or inconsistencies between the two implementations. Also any updates would have to be applied to both.
2 - My friend suggested spinning up a local server quietly in the background. This does sound like a possibility, but my main concern is that if I ever wanted to make a mobile build or something like that I think this wouldn’t work?
3 - Extract the gameplay logic into a Lua library which is shared between the Unity and Nakama project (not currently sure what the best way to actually handle this is) and have Unity execute this functionality directly when offline and via Nakama online. This sounds the most promising to me but I’m not actually sure how feasible it is.
If anyone could offer any suggestions or direction or tips it would be greatly appreciated!
Thanks 
Hi @Firebugs,
Some of your requirements seem a bit contradictory - I wouldn’t expect a turn-based game to have strict latency requirements, and both authoritative and offline play.
But shall you go down this route, I think option 3 is your best bet. Its feasibility however is difficult to foresee, given the complexity of the requirements.
Best
Hi @sesposito,
Thanks for your reply! Sorry I wasn’t clear, when I said “low latency requirements” I didn’t mean “low-latency” I meant that the requirements for latency weren’t important.
Also I might not be using the correct terminology so will try to explain again a little more clearly but I was thinking about the online (server authoritative multiplayer) and offline as two separate things. What I meant is: I want to create an online gameplay mode with lobbies where the server is in control of the gameplay and validates actions (playing cards, moving, attacking etc.) and then clients are responsible for the visual reconstruction of state changes and occasionally (on each client’s turn) sending a request to the server to make their move.
However, I also want players to be able to play the game offline in a separate game mode (against AI or just against other players locally, like pass-and-play) with the same gameplay validation / logic (playing cards, moving, attacking) but without requiring a network connection or other players.
My current understanding is that I would create a Lua library which abstracts the gameplay rules. Then nakama would load this library in it’s modules on the server side and unity would load this library on the client side (via something like moonsharp). Then if the player is playing an online game the gameplay is routed through nakama, but if they’re offline Unity makes calls directly into the library inside Unity. I’m feeling more confident about this approach now, but I’m honestly still not certain.
Okay I see, thanks for the clarification. Then yes, I think the approach definitely makes sense. Personally, I’d try to define very well the message protocol between client and server and make it work authoritatively. If the boundaries are well defined, you should be able to swap out the network calls for API calls that are handled locally by AI for offline play.
1 Like