Construct 3
Use the ZokoGames addon in Construct 3 with tagged actions, conditions and expressions, with event sheet recipes for ads, saves and scores.
The ZokoGames addon (zokogames.c3addon, plugin id zokogames, SDK v2, single global object) lives in packages/sdk-engines/construct3. All SDK work runs on the page's main thread in a DOM-side script (c3runtime/domside.js), so it works with Construct's worker mode; the runtime exchanges plain results with it. Terms such as "midgame" and "rewarded" are in the glossary.
Status (1.7.2): the addon was installed in the Construct 3 r506.4 editor, and exports made by the editor pass the production check (12 areas, with 1.7.1). Seven further exports covering non-worker mode, rooms with two players, store errors, settings, mute and offline events, request blocking and behaviour before Initialize ran locally on 2026-11-23; version 1.7.2 fixes the room values after Update room. If the addon fails to load, send the Construct version and the exact error to support.
Install#
Download the Construct 3 plugin: /sdk-engines/zokogames-construct3-1.7.2.zip. It holds the installable zokogames.c3addon (built from the construct3 folder in the repository), the README and the changelog.
/sdk-engines/construct3.zip is always the latest version. Checksums: /sdk-engines/SHA256SUMS. Index of every engine package with its version, size and SHA-256: /sdk-engines/engines.json.
- Unzip the download and install
zokogames.c3addon(not the zip) through Menu > View > Addon Manager > Install new addon. If you build from the repository,pnpm --filter @zoko/sdk-engines packagewriteszokogames-construct3-<version>.zipwith the same file (see the overview). - Restart Construct 3, then Insert new object > ZokoGames. It is a single global object, so one is enough. The addon uses Addon SDK v2 and needs Construct 3 r397 or newer.
- Run the Initialize action at the start of the first layout. The DOM-side script loads
https://sdk.zokogames.com/zokogames-sdk-v1.jsitself when the page does not have it, so you do not edit any export file. - Export as an HTML5 website and upload the zip.
Which path#
| You are | Do this |
|---|---|
| A Construct hobbyist with a finished game | Install the addon, add Initialize, the ad events below, export as HTML5 website, upload. No scripting needed. |
| Comfortable with scripting | The same SDK is reachable from a script when worker mode is off (see Scripting). |
Tags, results and errors#
Every asynchronous action takes a Tag. When the call ends, On request completed (with that tag) or On request failed (with that tag) triggers; On any request failed triggers for every failure. Use one tag per request in flight. Every action is asynchronous, so System: Wait for previous actions to complete placed after it waits until the call has ended.
| Expression | Contents |
|---|---|
ResultString |
The last result when it is text: a token, an invite link, a saved item. |
ResultNumber |
The last result as a number (booleans are 1 and 0; Check ad blocker reads ResultNumber, 1 means blocked). |
ResultJSON |
The last result as JSON (the friends page, the account link answer). |
ErrorCode, ErrorMessage, ErrorContainerId |
Details of the last failure. ErrorContainerId is set for banner errors. |
A working event sheet#
The sheet below covers init, a midgame ad, a rewarded ad, gameplay start and stop, save and load, and a leaderboard score. Use a global variable Coins, Best and RewardPending.
System: On start of layout (first layout)
-> ZokoGames: Initialize (tag "init")
ZokoGames: On request completed ("init")
-> ZokoGames: Get saved item (tag "load", key "best") // load; saves are asynchronous in worker mode
ZokoGames: On request completed ("load")
+ ZokoGames: has saved item "best" (compare HasSavedItem("best") = 1)
-> Set Best to int(SavedItem("best"))
ZokoGames: On request failed ("init") // SDK missing or blocked: just start
-> Go to layout "Menu"
ZokoGames: On request completed ("load") or On request failed ("load")
-> Go to layout "Menu" // a failed load (data module off) must not block the game
// Ads: pause on start, resume on finish AND error. Never pause in the action itself.
ZokoGames: On ad started
-> System: Set time scale 0 ; Audio: Set silent
ZokoGames: On ad finished
-> System: Set time scale 1 ; Audio: Set not silent
+ System: Compare variable RewardPending = 1
-> Add 10 to Coins ; Set RewardPending to 0
ZokoGames: On ad error
-> System: Set time scale 1 ; Audio: Set not silent ; Set RewardPending to 0
// Loading: the portal's loading bar ends here (once, when the menu can be used)
Menu layout: On start of layout
+ ZokoGames: Is available
-> ZokoGames: Loading stop (tag "ls")
// Gameplay start/stop
Game layout: On start of layout (player can act)
+ ZokoGames: Is available
-> ZokoGames: Gameplay start (tag "gs")
Game over (or pause menu opened)
+ ZokoGames: Is available
-> ZokoGames: Gameplay stop (tag "gx")
// Midgame ad at a natural break (e.g. on the game-over screen)
Game over screen: On start of layout
+ ZokoGames: Is available
-> ZokoGames: Request ad (type midgame, tag "mid")
// Rewarded ad
Reward button: On clicked
+ ZokoGames: Is available
-> Set RewardPending to 1 ; ZokoGames: Request ad (type rewarded, tag "rew")
// Save
Round ends and Score > Best
-> Set Best to Score ; ZokoGames: Set saved item (tag "save", key "best", value str(Best))
// Leaderboard (signed-in players only; board enabled in the console)
Round ends
+ ZokoGames: Is available
-> ZokoGames: Submit score (tag "score", encrypted "", score Score)
// Mute setting
ZokoGames: On settings changed
+ ZokoGames: Is mute requested
-> Audio: Set silent
ZokoGames: On settings changed
+ Else
-> Audio: Set not silentTwo traps are built into this sheet on purpose:
- On request completed ("rew") is not "ad finished". When an ad is unfilled, blocked or in cooldown, the SDK delivers On ad error and the action still completes, so grant rewards in On ad finished only. When the SDK is disabled, the action fails (On request failed) and neither ad event fires, so never leave the game paused in the action's own event.
Submit scorewith an emptyencryptedvalue works only on a board without an encryption key (the plain score is validated against the board rules). A keyed board counts only a correctly encrypted payload (leaderboards), and the addon has no encryption helper: compute the score on your server and use the server API, or leave the board keyless for a casual game. A player who is not signed in is not ranked.
Purchases#
ZokoGames: On request completed ("init") + ZokoGames: Is store available
-> Shop button: Set visible ; ZokoGames: Get catalogue items (limit 50, offset 0, tag "cat")
ZokoGames: On request completed ("cat")
-> loop 0..StoreItemCount-1: row with StoreItemName(loopindex), StoreItemPrice(loopindex), StoreItemCurrency(loopindex)
Buy button: On clicked
-> ZokoGames: Buy item (StoreItemSku(selected), tag "buy")
ZokoGames: On request completed ("buy")
-> grant PurchasedItemId ; ZokoGames: Get purchase token (tag "tok") // then send PurchaseToken to your server
ZokoGames: On request failed ("buy") + Last error is "purchaseCancelled" -> (nothing)
ZokoGames: On request failed ("buy") + Last error is "userNotAuthenticated" -> ZokoGames: Show login prompt (tag "login")Verify ownership on your server (see in-game purchases). StoreItemPrice is -1 when there is none and InventoryQuantity is -1 when not counted.
Actions#
| Group | Actions |
|---|---|
| Start-up | Initialize |
| Ads | Request ad (midgame or rewarded), Check ad blocker |
| Banners | Request banner (id, size 728x90, 300x250, 320x50, 468x60 or 320x100, x, y, w, h), Request responsive banner (id, x, y, w, h), Clear banner, Clear all banners |
| Game | Gameplay start, Gameplay stop, Loading start, Loading stop, Report loading progress (0 to 100), Happytime, Report completed percentage, Set game context (JSON), Clear game context |
| Multiplayer | Update room, Set room public, Left room, Create invite link, Show invite button and Hide invite button (deprecated) |
| User | Get user, List friends, Get user token, Show login prompt, Show account link prompt, Submit score |
| Store | Get catalogue items, Get player inventory, Buy item, Consume item, Set sandbox, Get purchase token, Get payment provider user token (deprecated) |
| Cloud save | Get saved item, Set saved item, Remove saved item, Clear saved data |
| Achievements | Unlock achievement (key), List achievements |
| Analytics | Track order, Track event (name, params JSON; SDK 1.7.0) |
Banner rectangles are in canvas CSS pixels with the origin at the top left; the addon converts them into fractions of the canvas. Request banners on menu layouts only.
Conditions#
- Status: Is initialized, Is available (false when the SDK is disabled), Is QA tool.
- Requests: On request completed, On request failed, On any request failed, Last error is (code).
- Ads: On ad started, On ad finished, On ad error, Is ad playing.
- Settings: On settings changed, Is mute requested, Is chat disabled.
- Offline: On offline changed, Is offline, and the expression
IsOffline(1 or 0). Before 1.6.1 that expression failed in the event sheet; update the addon if you use it. - Multiplayer: Is instant multiplayer, On join room.
- Achievements: On achievement unlocked.
- Account: On auth changed, Is logged in, Is account available.
- Store: Is store available.
Kids mode. Since version 1.5.0 the wrapper exposes it: Is kids mode (KidsMode) is true when the game runs in kids mode (a game with the kids flag, or a player in kids mode); hide chat, rooms, sign-in prompts and shop screens then. A portal that does not send the field gives false, so also keep honouring Is chat disabled, which the portal sets to true in the same cases. To test it, add ?kidsMode=true to the page address in local mode. See kids mode.
Expressions#
Environment, SdkVersion, MuteAudio, DisableChat, IsOffline, InviteParam(key), InviteParamsJSON, UserName, UserPictureUrl, UserId (never trust it on a server; verify the token), UserToken, FriendCount, FriendsTotal, FriendsHasMore, FriendName(i), FriendId(i), FriendPictureUrl(i), Locale, CountryCode, DeviceType, SavedItem(key), HasSavedItem(key), ErrorCodes(module) (comma separated codes for ad, banner, user, data, store, room or general), ResultJSON, ResultString, ResultNumber, ErrorCode, ErrorMessage, ErrorContainerId, and store expressions StoreItemCount, StoreItemSku(i), StoreItemName(i), StoreItemDescription(i), StoreItemImageUrl(i), StoreItemPrice(i), StoreItemCurrency(i), StoreItemConsumable(i), InventoryCount, InventorySku(i), InventoryName(i), InventoryDescription(i), InventoryImageUrl(i), InventoryQuantity(i), PurchasedItemId, PurchaseToken, XsollaUserToken (deprecated name for the purchase token), and the achievement expressions AchievementCount, AchievementKeyAt(i), AchievementNameAt(i), AchievementDescriptionAt(i), AchievementPointsAt(i), AchievementUnlockedAt(i), AchievementIsUnlockedAt(i) (1 or 0), LastUnlockReason, LastAchievementKey, LastAchievementName and LastAchievementPoints. Run List achievements before the ...At(i) expressions; Unlock achievement fills the LastAchievement... ones. For guests and unknown keys the action still completes, and LastUnlockReason is guest, not_found, not_live, rate_limited or error; AchievementUnlockedAt(i) is empty while the achievement is locked. See achievements.
Scripting#
You can call the SDK from a script, but only when Use worker is off in Project Properties: with a worker the runtime has no window, so globalThis.ZokoGames does not exist in the script. Run scripts only after Initialize has completed.
// Script event, after the "init" request completed. Needs Use worker = No.
const SDK = globalThis.ZokoGames.SDK;
const user = await SDK.user.getUser();
runtime.globalVars.PlayerName = user ? user.username : "guest";Room data channel#
Added in SDK 1.3.0. The room data channel lets the players of one room exchange small JSON messages and share a tiny state that only the host writes, so a simple multiplayer game needs no server of its own. It is for game data, not text chat. It exists after updateRoom (or after joining from an invite) and ends with leftRoom, needs a signed-in player and a portal with realtime enabled (otherwise roomUnavailable), and has these limits: 8 KB per message or patch, 20 messages per second, 64 KB of state, state keys of 1 to 40 characters of A-Z a-z 0-9 _ . : -. Messages are never echoed back to their sender on the portal; the first player in the room is the host. The full rules and error codes (notInRoom, notHost, payloadTooLarge, stateTooLarge, unknownMember, rateLimited, roomUnavailable) are in the game module and the multiplayer guide.
The Room category carries it. Message and value parameters accept text or numbers: valid JSON ({"x":1}, 5, true) is sent as that JSON value, anything else as plain text. The room state, member list, host and your own id are cached from the room events, so the expressions work in worker mode. On localhost the SDK's local mode makes two browser tabs that join the same room id behave like two players.
| Kind | ACEs |
|---|---|
| Actions | Send room message (tag, data), Send room message to member (tag, member id, data), Set room state key (tag, key, value; host only), Remove room state key (tag, key; host only) |
| Triggers | On room message, On room state changed, On room members changed, On room host changed, On room left (SDK 1.7.0; expressions RoomLeftReason, RoomLeftRoomId), On room error |
| Condition | Is room host |
| Message expressions | RoomMessageData, RoomMessageFrom, RoomMessageDirect, RoomMessageSeq, RoomMessageValue(key) |
| State expressions | RoomStateJSON, RoomStateValue(key), RoomStateChangedKeys, RoomStateChangedBy, RoomStateRev |
| Member expressions | RoomMemberCount, RoomMemberIdAt(i), RoomMemberNameAt(i), RoomMemberPictureUrlAt(i), RoomHostId, RoomSelfId |
| Error expressions | RoomErrorCode, RoomErrorMessage (for the room error trigger; request failures still use On request failed) |
ZokoGames: On room host changed
+ ZokoGames: Is room host -> ZokoGames: Set room state key (key "turn", value "X", tag "turn")
Board: On cell clicked -> ZokoGames: Send room message ("{""cell"":" & Cell & "}", tag "move")
ZokoGames: On room message -> Board: Place cell ZokoGames.RoomMessageValue("cell")
ZokoGames: On room state changed -> Text: Set text to ZokoGames.RoomStateValue("turn")Export settings that matter on the web#
- Export as HTML5 website and zip the export folder contents so
index.htmlis at the archive root. - Offline support: No (it adds a service worker; the validator warns
service_workerbecause it can clash with the portal's own offline handling). Use worker: Yes is supported. Minify script: Simple or Advanced. - No pre-compression. Construct does not write
.bror.gz; upload the export as is. The game origin serves a.bror.gzsuffix with the matchingContent-Encoding, but Construct requests plain names, so renamed files would break. The initial-download estimate uses uncompressed sizes: compress images (WebP) and audio (Opus or AAC), and put large media in a second layout loaded once the first is interactive. Limits: 1,500 files, 250 MB unpacked, about 50 MB initial download (20 MB for mobile); see first frame fast. - Canvas sizing. The frame size changes with fullscreen and rotation. Set the project's fullscreen scaling (Project Properties > Fullscreen mode) to a letterbox or scale-outer mode so the layout fits every required resolution.
- Audio unlock. Browsers keep audio suspended until the first click or tap. Start music from a "tap to play" button on the first layout, not on start of layout.
- Fullscreen. Prefer the fullscreen button in the portal's frame bar (it fullscreens the whole frame). The frame permits fullscreen, so Construct's Request fullscreen works from an input event, but it fullscreens only your canvas; do not add a competing button.
- Memory. Large projects load every layout's data up front. Split rarely used layouts and keep sprite sheets small, especially for mobile.
- Loading. In a loader layout run Loading start once, Report loading progress (
loadingprogress * 100) each tick, and Loading stop when the first game layout starts.
After an ad, a sign-in or account-link prompt or a checkout, keyboard focus goes back to the game frame and its canvas by itself, so the player's keys work again without a click.
Chat reports, screenshots and storage mirror#
Since SDK 1.4.0: the action Report chat message (name, message, reason, optional user id, room id and context JSON), the actions Set screenshot provider and Answer screenshot with the condition On screenshot requested, and Mirror localStorage to cloud save with the condition On mirror error. By default the runtime canvas answers the portal's screenshot request. The Local storage object keeps its data in IndexedDB, so the mirror does not copy it; use the Data actions for those saves. The editor preview uses the simulator.
Ad rules#
There are no prerolls: your game cannot request an ad before it starts. Midgame is the only interstitial type, so an interstitial or commercial break from another platform becomes a midgame ad (Request ad with type midgame); the only other type is rewarded. In local mode (testing on localhost, outside the portal) a midgame request fails with On ad error with adCooldown until your game has called the Gameplay start action or 30 seconds of visible page time have passed. On the portal the first midgame ad needs the Gameplay start action first as well, so call it when the player takes control (a game that never calls it gets midgame ads 30 seconds after play begins). Rewarded ads are not held back by this. Details: ads reference and ads guide.
Test locally#
There is no separate simulator. When the page's host is localhost, 127.0.0.1 or a *.localhost name, the JavaScript SDK runs its own local mode: a three-second overlay for each ad, a fake player, a localStorage cloud save and a three-item test store, so the same events fire as on the portal. On any other host the environment is disabled, and Is available is false.
- If your preview URL is not a localhost address (for example a preview served from the editor's own web host or over the local network), add
?useLocalSdk=trueto the preview URL, or export the project and serve the folder with a local web server. - A second midgame request within three minutes fails with
adCooldown(fires On ad error): the real rule, so your event sheet must cope. - Useful switches:
?sdk_debug=true,?ad_response=unfilled,?user_response=logged_out. - Then open the Preview tool with your local address and watch the checklist tick.
Known pitfalls#
- Addon will not install. Install
zokogames.c3addon, not the zip. - A condition never fires. The tag in On request completed must equal the tag passed to the action, and only one request per tag should be in flight.
- Actions run but nothing happens. Run Initialize first and wait for its completion.
sdkNotLoaded. Offline or the SDK host is blocked; the preview needs internet access to load the script.- Game stays paused or silent. Resume in On ad error as well as On ad finished.
- Banner in the wrong place. Rectangles are canvas CSS pixels, origin top-left.
- Saved item is empty right after a load. Reads are asynchronous: wait for the tag's On request completed before reading
SavedItem.
Next#
- Check your build against the build validation rules and the launch checklist.
- Upload and publish: submission walkthrough.
- Other engines and shared rules: engines overview.