# Full passive turn-based multiplayer example somewhere?

**URL:** <https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339>\
**Category:** Game Design\
**Tags:** getting-started\
**Created:** [February 2, 2021, 1:03pm UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339 "2021-02-02T13:03:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kragil](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/kragil/32/481_2.png) [@kragil](https://forum.heroiclabs.com/u/kragil)\
**Post date:** [February 2, 2021, 1:03pm UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/1 "2021-02-02T13:03:35Z")

</div>

Hello,

i learn best when I have running examples that I can edit and learn from.  
SO … is there a complete running example for passive turn-based multiplayer, where the players don’t have to be online at the same time? That would be a great help for me.  
Thanks!

---

<div class="post-metadata">

**Author:** ![kragil](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/kragil/32/481_2.png) [@kragil](https://forum.heroiclabs.com/u/kragil)\
**Post date:** [February 7, 2021, 3:58pm UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/2 "2021-02-07T15:58:46Z")

</div>

I guess not. Too bad.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [February 7, 2021, 10:47pm UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/3 "2021-02-07T22:47:21Z")

</div>

Hi @kragil welcome 👋

As you’ve noticed there’s no official tutorial on how to implement a passive (often called asynchronous) multiplayer approach like you see in games like Words With Friends. This is not because its complicated to implement but it’s actually quite easy to achieve. The steps to follow are:

- Use the storage engine features in the server with write permissions set to 0 (zero) so that only server-side functions can change the state of the storage object.
- Use a couple of RPCs to implement the input checks and apply the state changes to represent the transition between turns in the asynchronous multiplayer match.
- Use an in-app notification (with optional push notifications) to indicate when the match has ended and rewards are distributed).
- Track which matches a player has active in a second storage object that is their “active\_matches” object.

I’ve made a note for us to add this to the official documentation in the future but in the meantime you could ask any questions you have as you implement it for your game.

---

<div class="post-metadata">

**Author:** ![kragil](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/kragil/32/481_2.png) [@kragil](https://forum.heroiclabs.com/u/kragil)\
**Post date:** [February 8, 2021, 5:37am UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/4 "2021-02-08T05:37:48Z")

</div>

OK, thanks a lot for the answer.  
Just be clear:  
So I can’t use the Matchmaker, the Authoritative Multiplayer features and the Match Handler?  
I should implement them myself? If so could I maybe misuse the tournament feature for some parts?  
Thanks again.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [February 8, 2021, 2:14pm UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/5 "2021-02-08T14:14:26Z")

</div>

> So I can’t use the Matchmaker, the Authoritative Multiplayer features and the Match Handler?

@kragil That’s not quite true though it depends on the multiplayer experience you want to offer. You can definitely use the authoritative multiplayer engine (match handlers) with a “suspend/resume” approach to progress the game state but that would be more useful if you want to offer a hybrid of the asynchronous multiplayer model and the active multiplayer model.

For example if you want players who are both online to feel the “active/rapid” experience of their multiplayer match but also allow players to come back if they have to go offline and resume their turn later. As always with multiplayer the devil is in the details.

Do you have a reference example for the type of multiplayer game you want to create?

---

<div class="post-metadata">

**Author:** ![kragil](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/kragil/32/481_2.png) [@kragil](https://forum.heroiclabs.com/u/kragil)\
**Post date:** [February 9, 2021, 9:26am UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/6 "2021-02-09T09:26:10Z")

</div>

@novabyte Id like to do something like Draw Something, where you just start a match, do something and then close the app and somebody else can pick up from there and then the next time you log in somebody did something and it is your turn again.

---

<div class="post-metadata">

**Author:** ![dkozlov](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/dkozlov/32/502_2.png) [@dkozlov](https://forum.heroiclabs.com/u/dkozlov)\
**Post date:** [February 10, 2021, 9:32am UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/7 "2021-02-10T09:32:14Z")

</div>

@kragil You can look for example here:

I am using nk.StorageWrite with custom json data

github /challenge-league/nakama-plugin-challenge-league/blob/a9406e680efd230069f9aa4c66f4b9febb099c36/match\_state.go#L168

github /challenge-league/nakama-plugin-challenge-league/blob/master/match.go

---

<div class="post-metadata">

**Author:** ![kragil](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/kragil/32/481_2.png) [@kragil](https://forum.heroiclabs.com/u/kragil)\
**Post date:** [February 10, 2021, 10:16am UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/8 "2021-02-10T10:16:28Z")

</div>

@dkozlov Hey cool! Thank you. I will have a look, although I am not a Go programmer, but I guess I will manage 😉

> <https://github.com/challenge-league/nakama-plugin-challenge-league/blob/master/match_state.go>

> <https://github.com/challenge-league/nakama-plugin-challenge-league/blob/master/match.go>

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [February 10, 2021, 10:19am UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/9 "2021-02-10T10:19:48Z")

</div>

@kragil I would definitely use a suspend/resume pattern with the Draw Something style of game. Have each match handler track its state and when the user who’s turn it is leaves the match handler you can suspend the match so that it can be resumed when they come back.

You’ll need to bookkeep a little things like what active matches each user has that they’re part of and store the match state as a serialized object to JSON. The whole pattern is probably around 200-300 lines of code to implement.

---

<div class="post-metadata">

**Author:** ![kragil](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/kragil/32/481_2.png) [@kragil](https://forum.heroiclabs.com/u/kragil)\
**Post date:** [February 10, 2021, 6:57pm UTC](https://forum.heroiclabs.com/t/full-passive-turn-based-multiplayer-example-somewhere/1339/10 "2021-02-10T18:57:16Z")

</div>

@novabyte Now I am confused. I thought I can’t match players if they are not online at the same time and therefor I cannot use the match handler. Is that not true?
