Documentation

Cloud Code

Version: 3.0.0  
Unity 6.7 (6000.7)+
Open Unity Dashboard

Cloud Code

Version: 3.0.0  
Unity 6.7 (6000.7)+

Turn-based game workflow

Follow this workflow to create a turn-based multiplayer game with CloudBehaviours.
Read time 2 minutesLast updated 12 days ago

Important
This page describes an experimental feature that might change significantly before release. It's not recommended to use or rely on experimental features in production environments due to potential instability.
A
MultiplayerSession
-scoped CloudBehaviour suits a turn-based game. One instance holds the shared match state, and every player in the session receives its updates. Start from a
MultiplayerSession
-scoped CloudBehaviour, then add turn notifications, a turn clock, and hidden information.
To create a turn-based game with CloudBehaviours, complete the following tasks:

Prerequisites

Before you start, complete Get started with CloudBehaviours with a
MultiplayerSession
-scoped CloudBehaviour.

Notify players when a turn changes

Declare a public event on your cloud class, and invoke the event when a turn ends. Each time the event fires, every client in the session receives a message, so each player's game reacts as soon as a turn changes, without polling. For how to declare a push channel and listen for it in your game, refer to Push channels in CloudBehaviours.

Time out an unresponsive player

Schedule a server-authoritative timer when a turn starts, so a player who closes the game can't hold up the match. Mark the endpoint that the timer calls with
[CloudCodeAccess(Access.Service)]
, so no player can call the endpoint directly. The timer can still call it. For how to schedule and cancel the timer, refer to Timers in CloudBehaviours. For how to restrict the endpoint, refer to Access control in CloudBehaviours.
Note
A timer callback runs with no player identity. If your timeout logic needs to know which player it's timing out, pass the player ID as an argument to the scheduled endpoint, rather than reading the player ID from the calling context.

Show each player only their own hidden information

For a game with hidden information, such as a card game, define a per-player view of the state that each player can access. Cloud Code builds each player's view and keeps it up to date automatically. For how to define the view, refer to Per-player state views in CloudBehaviours.

Additional resources