Asynchronous multiplayer

The Construct 3 plugin supports asynchronous multiplayer. For more details, see the HTML5 section.

Multiplayer initialization

To get started, use the Initialize multiplayer action. It performs initial initialization and loads game sessions of opponents.

Initialization parameters:

Parameter

Type

Description

Sessions count

number

Number of sessions to load (maximum 10).

Turn time

number

Maximum opponent turn time in milliseconds.

Meta

JSON

Object with data for session selection.

For more details about parameters, see the main article.

After successful multiplayer initialization, the On multiplayer initialization trigger will be activated. To process the received opponent sessions, use the For each opponent loop inside it. The following expressions are available in the loop:

  • Current session player data — player data in the current session by the avatar or name key.
  • Current session ID in sessions list.

To get session metadata, use the Get current session metadata action.

Recording a game session

Available actions:

  • Commit transaction — use to commit transactions. The action accepts a JSON object with data.

  • Push session — use to save the session. The action accepts a JSON object with session metadata.

For more details, see the main article.

Working with sessions

In Construct 3, working with sessions is done only through events. For this, the On multiplayer session transactions and On multiplayer session finish triggers are used.

In the On multiplayer session transactions trigger, the following are available:

  • The Session ID in event expression.

  • The For each transaction loop — for processing the list of incoming opponent transactions. The following expressions are available in the loop:

    • Current transaction ID in transactions list.
    • Current transaction time in transactions list.

    To get transaction data, use the Get current transaction data action.

In the On multiplayer session finish trigger, the Session ID in finish event expression is available.

To initiate sending sessions to handlers, call the Mark gameplay start action. Pausing is done by calling Mark gameplay stop.

For more details about working with sessions, see the main article.

Usage example

Construct 3 screenshot: the async multiplayer settings screen using the YandexGamesSDK plugin. Table with three columns (each cell in the third column has "+ Add action" and "+ Add..." buttons) and 8 rows. Row 1 — "OK" icon and text "start", "On clicked", "{:} InitMeta | Parse JSON string "{""meta1"":{""min"":7,""max"":9}}""  "YandexG... | Initialize multiplayer. Number of sessions: 1, turn time: 20000 ms, meta: {:} InitMeta"  settings icon "System | Wait for previous actions to complete"  "YandexG... | Mark gameplay start". Row 2 — "YandexGames…", "Multiplayer initialized", empty cell. Row 3 — "YandexGames…", "For each opponent", letter "T" icon in a dashed square and text "Text2 | Set text to YandexGamesSDK.Current session ID in the session list". Row 4 — "YandexGames…", "Session transactions received", empty cell. Row 5 — "YandexGames…", "For each transaction", "YandexG… | Get current transaction data and save to {:} payload"  letter "T" icon in a dashed square and text "Text2 | Set text to payload.Get("data")". Row 6 — "YandexGames…", "Session ended", letter "T" icon in a dashed square and text "Text2 | Set text to "End"". Row 7 — "OK" icon and text "commit", "On clicked", "settings icon "System" | Subtract 1 from hp"  "{:} transacti... | Parse JSON string "{""data"":"&hp&"}""  "YandexG... | Write transaction with data {:} transaction". Row 8 — "OK" icon and text "end", "On clicked", "{:} pushMeta | Parse JSON string "{""meta1"":8}""  "YandexG... | Save session with metadata {:} pushMeta".


Repository