Godot 3
Use ZokoGames from Godot 3 HTML5 exports with the zokogames addon, its autoload, signals and yield style GDScript 1 API, plus encryption and the IndexedDB mirror.
The zokogames addon (packages/sdk-engines/godot3/addons/zokogames) targets Godot 3 HTML5 exports (3.5 and 3.6 LTS are the targets, 3.3 and 3.4 should work, 3.0 to 3.2 are not supported). It has the same public API as the Godot 4 addon: the same autoload ZokoGames, the same method names and the same signals, so a project can move between the two. It is written in GDScript 1 (no await, no lambdas) and calls the JavaScript SDK through the JavaScript singleton, using a small bridge (window.ZokoBridge) defined in the export's HTML shell. Outside a browser (in the editor, or a desktop run) a built-in simulator answers instead, so the same code runs everywhere. Terms such as "midgame" and "rewarded" are in the glossary.
Status (1.8.0): run headless in the official Godot 3.6.3 editor on macOS. The addon imports with no errors or warnings (warnings treated as errors), enabling the plugin registers the autoload, every public method and signal behaves as documented in simulator mode, and the HTML5 export contains the bridge and runs in a browser. Godot 3.3 to 3.5 are not verified, and a run against the live portal is not either. Send the Godot version and the exact error to support if the first import fails.
On Godot 4 this addon refuses to start (init() fails with unsupportedEngine); use the Godot 4 page there.
Install#
Download the Godot 3 plugin: /sdk-engines/zokogames-godot3-1.8.0.zip (the same files as the folder in the repository).
/sdk-engines/godot3.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. The source is also published at github.com/zokogames/zokogames-godot3. It is also in the Godot Asset Library (asset 5620): search for ZokoGames in the editor's AssetLib tab (Godot 3), or install from the zip.
- Unzip the download and copy its
addons/zokogamesfolder into your project'sres://addons/folder (createaddonsif it does not exist). It holdsplugin.cfg,plugin.gd,zokogames.gd(the autoload),zoko_banner.gdandexport/zokogames_shell.html. - Project > Project Settings > Plugins: enable ZokoGames. This registers the autoload
ZokoGames(res://addons/zokogames/zokogames.gd) and thezokogames/simulator/*settings. - Project > Export: add an HTML5 preset and set Custom HTML Shell (Options tab > HTML) to
res://addons/zokogames/export/zokogames_shell.html. The shell loadshttps://sdk.zokogames.com/zokogames-sdk-v1.jsbefore the engine, createswindow.ZokoBridge, and reports the engine download to the portal's loading bar. With your own shell, add the script tag to<head>and copy the bridge block from the supplied one. yield(ZokoGames.init_async(), "completed")once at startup, before any other call.- Optional: add a
ZokoBannernode (zoko_banner.gd) over the space you can spare for a banner. Theexamples/folder next to the addon haszoko_demo.gdandzoko_store.gd.
Without the custom shell window.ZokoBridge does not exist. The addon logs a warning and falls back to the simulator, so the game runs but uses no real ads, users or saves.
Starter kit#
A ready Godot 3 project with the addon, the shell and a small demo scene: /starter-kits/godot3.zip. See the starter kits page.
What differs from Godot 4#
| Godot 4 | Godot 3 |
|---|---|
await ZokoGames.get_user_async() |
yield(ZokoGames.get_user_async(), "completed"), which returns the same Dictionary |
callback: Callable |
callback: a FuncRef, funcref(self, "_on_done") |
ZokoGames.ad_started.connect(f) |
ZokoGames.connect("ad_started", self, "_on_ad_started") |
The addon pauses the tree and mutes the Master bus while an ad plays and applies the portal's mute setting (pause_game_during_ads, mute_audio_during_ads, follow_portal_mute, all true) |
The same properties and defaults; your own nodes that must react during an ad need pause_mode = PAUSE_MODE_PROCESS |
JavaScriptBridge |
JavaScript |
An _async call returns a request object (with id, done, result and the signal completed(result)), and yield(..., "completed") gives the result Dictionary. Every request completes on a later frame, so the yield cannot miss it.
A working script#
Put this in a script on a node in your first scene (or in your own autoload). It covers init, a midgame ad, a rewarded ad, gameplay start and stop, save and load, and a leaderboard score.
extends Node
func _ready() -> void:
pause_mode = PAUSE_MODE_PROCESS # keep running while an ad pauses the tree
var res = yield(ZokoGames.init_async(), "completed")
if not res.ok:
push_warning("ZokoGames unavailable: %s" % res.error.code)
# The addon pauses the tree and mutes Master during an ad, and follows the portal's mute setting
# (pause_game_during_ads, mute_audio_during_ads, follow_portal_mute): no ad or mute handlers needed.
var level = int(ZokoGames.data_get_item("level", "1")) # load: synchronous Strings
start_game(level)
# Call when the player takes control, and when play stops.
func on_play_start() -> void:
if ZokoGames.is_available():
ZokoGames.gameplay_start()
func on_play_stop() -> void:
if ZokoGames.is_available():
ZokoGames.gameplay_stop()
func show_midgame() -> void:
var res = yield(ZokoGames.request_ad_async("midgame"), "completed") # completes after the ad is over
if not res.ok:
print("no ad: ", res.error.code) # adCooldown, unfilled, adblock ...
func on_reward_button() -> void:
var res = yield(ZokoGames.request_ad_async("rewarded"), "completed")
if res.ok:
grant_reward() # reward only after the ad finished
func save_progress(level: int) -> void:
var r = ZokoGames.data_set_item("level", str(level)) # synchronous, uploaded in the background
if not r.ok:
push_warning(r.error.code) # for example dataLimitExceeded
func submit_score(score: float) -> void:
var user = yield(ZokoGames.get_user_async(), "completed")
if not user.ok or user.result == null:
return # guests are not ranked
var r = yield(ZokoGames.submit_score_async("", score), "completed") # "" works only on a board WITHOUT an encryption key
if not r.ok:
print(r.error.code)
func start_game(_level: int) -> void:
pass
func grant_reward() -> void:
passLeaderboard scores and encryption#
A board with an encryption key counts only a correctly encrypted payload (leaderboards). Since plugin 1.8.0, encrypt_score_async(score, KEY) seals the score with your board key and returns the payload for submit_score_async; "" works only for a board without a key.
const BOARD_KEY = "paste-your-board-key-here"
func submit_secure_score(score: float) -> void:
var sealed = yield(ZokoGames.encrypt_score_async(score, BOARD_KEY), "completed")
if not sealed.ok:
print(sealed.error.code) # userNotAuthenticated for guests, invalidArgument for a bad score or key
return
var r = yield(ZokoGames.submit_score_async(sealed.result, score), "completed")
if not r.ok:
print(r.error.code)The optional third argument earned_at (Unix milliseconds, default 0 for a live run) seals the delayed copy of a score. A key inside a build stops casual edits, not a determined player: for real stakes compute the score on your server and use the server API.
How calls work#
GDScript names are snake_case. Every method that talks to the portal comes in two forms:
| Form | Example | Use it for |
|---|---|---|
| Callback | ZokoGames.get_user(callback) |
Fire-and-forget calls. The FuncRef is optional and last, except in store_get_catalog_items(callback, limit, offset) and store_get_player_inventory(callback, limit, offset), where it comes first, and in get_user_token(signing_key_type, callback). |
| Request | yield(ZokoGames.get_user_async(), "completed") |
Straight-line code. The name ends in _async. |
Both deliver a Dictionary, { "ok": true, "result": <value> } or { "ok": false, "error": { "code": "...", "message": "..." } } (request_ad takes a Dictionary of FuncRefs instead). All methods live directly on the autoload; there are no ad., game. or user. sub-objects.
| JavaScript | GDScript |
|---|---|
SDK.init() |
yield(ZokoGames.init_async(), "completed") or ZokoGames.init(callback); signal initialized(ok) |
SDK.environment |
ZokoGames.environment ("local", "zokogames" or "disabled"), ZokoGames.is_available(), ZokoGames.is_simulated, ZokoGames.is_qa_tool, ZokoGames.VERSION |
SDK.ad.requestAd(type, cbs) |
ZokoGames.request_ad(type, {"ad_started": f, "ad_finished": f, "ad_error": f}) (FuncRefs) or yield(ZokoGames.request_ad_async(type), "completed") |
SDK.ad.hasAdblock() |
ZokoGames.has_adblock(callback) or yield(ZokoGames.has_adblock_async(), "completed") |
SDK.banner.requestBanner(...) |
yield(ZokoGames.request_banner_async(id, width, height, window_rect), "completed") |
SDK.banner.requestResponsiveBanner(id) |
yield(ZokoGames.request_responsive_banner_async(id, window_rect), "completed") |
SDK.banner.clearBanner(id) / clearAllBanners() |
ZokoGames.clear_banner(id) / ZokoGames.clear_all_banners() |
SDK.banner.hideAllBanners() / showAllBanners() (1.8.0) |
ZokoGames.hide_all_banners() / ZokoGames.show_all_banners() (and _async) |
SDK.game.gameplayStart() / gameplayStop() |
ZokoGames.gameplay_start() / ZokoGames.gameplay_stop() |
SDK.game.loadingStart() / loadingStop() / loadingProgress(n) |
ZokoGames.loading_start() / loading_stop() / loading_progress(n) |
SDK.game.happytime() |
ZokoGames.happytime() |
SDK.game.reportGameCompletedPercentage(n) |
ZokoGames.report_game_completed_percentage(n) |
SDK.game.setGameContext(obj) / clearGameContext() |
ZokoGames.set_game_context(dict) / ZokoGames.clear_game_context() |
SDK.game.updateRoom(u) / leftRoom() |
ZokoGames.update_room(dict) / ZokoGames.left_room() |
SDK.game.inviteLink(p) / getInviteParam(k) |
yield(ZokoGames.invite_link_async(dict), "completed") / ZokoGames.get_invite_param(key) |
SDK.game.showInviteButton(p) / hideInviteButton() |
yield(ZokoGames.show_invite_button_async(dict), "completed") / ZokoGames.hide_invite_button() |
SDK.game.settings |
ZokoGames.settings (disableChat, muteAudio), signal settings_changed |
SDK.game.isOffline, offline listener |
ZokoGames.is_offline, signal offline_changed(offline) |
SDK.game.isInstantMultiplayer / inviteParams |
ZokoGames.is_instant_multiplayer (alias is_instant_join) / ZokoGames.invite_params, signal join_room(params) |
SDK.user.isUserAccountAvailable / systemInfo |
ZokoGames.is_user_account_available / ZokoGames.system_info |
SDK.user.getUser() |
yield(ZokoGames.get_user_async(), "completed") |
SDK.user.getUserToken(opts) |
yield(ZokoGames.get_user_token_async(signing_key_type), "completed") |
SDK.user.showAuthPrompt() |
yield(ZokoGames.show_auth_prompt_async(), "completed"), signal auth_changed(user) |
SDK.user.showAccountLinkPrompt() |
yield(ZokoGames.show_account_link_prompt_async(), "completed") |
SDK.user.listFriends(opts) |
yield(ZokoGames.list_friends_async(page, size), "completed") |
SDK.user.submitScore(opts) |
yield(ZokoGames.submit_score_async(encrypted_score, score), "completed") |
SDK.user.encryptScore(score, key) (1.8.0) |
yield(ZokoGames.encrypt_score_async(score, key), "completed") |
SDK.game.gameId (1.8.0) |
ZokoGames.game_id / get_game_id() |
SDK.data.mirrorIndexedDB() (1.8.0) |
HTML shell option window.ZOKO_MIRROR_INDEXEDDB = true (Head Include); ZokoGames.stop_mirror_indexed_db() |
SDK.data.getItem(k) / setItem(k, v) |
ZokoGames.data_get_item(key, default) / ZokoGames.data_set_item(key, value); also data_has_key, data_remove_item, data_clear (all synchronous) |
SDK.store.* |
store_get_catalog_items_async, store_get_player_inventory_async, store_buy_item_async(item_id), store_consume_item_async(sku, qty), store_get_purchase_token_async(), is_store_available, store_set_sandbox(bool) (synchronous); signals purchase_completed(item_id), purchase_failed(error) |
SDK.achievements.list() / unlock(key) / onUnlock |
yield(ZokoGames.achievements_list_async(), "completed") / achievements_unlock_async(key), signal achievement_unlocked(achievement); see achievements |
SDK.analytics.trackOrder(p, o) |
yield(ZokoGames.track_order_async(provider, order), "completed") |
SDK.analytics.track(name, params) (1.7.0) |
ZokoGames.track(name, params) / track_async(name, params) |
Signals on the autoload: initialized, ad_started, ad_finished, ad_error(error), auth_changed, settings_changed, offline_changed, join_room, purchase_completed, purchase_failed. Connect them with ZokoGames.connect("ad_finished", self, "_on_ad_finished"). Error codes are in ZokoGames.ERROR_CODES (a Dictionary keyed by module, for example ZokoGames.ERROR_CODES.ad); ZokoGames.has_error_code(res, "purchaseCancelled") tests a result. unsupportedEngine is extra in this addon.
Kids mode. ZokoGames.settings.get("kidsMode", false) 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. Keep honouring ZokoGames.settings.disableChat as well. To test it, switch on zokogames/simulator/kids_mode. See kids mode.
Cloud save for user:// (IndexedDB mirror)#
The web export keeps user:// files in the browser's IndexedDB (/userfs). To save them to the player's cloud save, add this line in Export > HTML > Head Include:
<script>window.ZOKO_MIRROR_INDEXEDDB = true;</script>The shell restores the cloud copy before the engine starts and uploads later writes within a few seconds. The mirrored data may not exceed 1 MiB, and the data module must be enabled for the game. ZokoGames.stop_mirror_indexed_db() stops mirroring. ZokoGames.mirror_local_storage({"prefix": "save_"}) is the separate mirror for JavaScript-side localStorage; it does not see user:// files.
Room data channel#
The room data channel (SDK 1.3.0) lets the players of one room exchange small JSON messages and share a tiny state that only the host writes. It is for game data, not text chat. The limits and error codes are the same as in Godot 4: see the game module and the multiplayer guide. Payloads cross the bridge as JSON (numbers come back as float; convert with int()).
| JavaScript | Godot |
|---|---|
room.send(data, { to }) |
ZokoGames.room_send(data, to, cb) / room_send_async(data, to) / room_send_to(member_id, data, cb) |
room.onMessage(cb) |
signal room_message(message) (from, data, direct, seq, ts) |
room.setState(patch) |
room_set_state(patch, cb) / room_set_state_async(patch) (a null value removes the key) |
room.getState(), room.onState(cb) |
room_get_state(), room_get_state_value(key, default); signal room_state(state, change) |
room.members(), room.onMembers(cb) |
room_get_members(); signal room_members(members) |
room.isHost(), room.onHostChange(cb), room.selfId |
room_is_host(); signal room_host_changed(host_id, is_host); room_self_id() |
room.addLeftListener(cb) (1.7.0) |
signal room_left(reason, room_id) |
room.onError(cb) |
signal room_error(error) |
extends Node
func _ready() -> void:
yield(ZokoGames.init_async(), "completed")
ZokoGames.connect("room_message", self, "_on_message")
ZokoGames.connect("room_host_changed", self, "_on_host_changed")
yield(ZokoGames.update_room_async({"roomId": "match-1", "isJoinable": true}), "completed")
func _on_host_changed(_host_id, is_host) -> void:
if is_host:
ZokoGames.room_set_state({"turn": "X"})
func _on_message(message) -> void:
print(message.from, " played cell ", int(message.data.cell))
func play_cell(cell: int) -> void:
yield(ZokoGames.room_send_async({"cell": cell, "mark": "X"}), "completed")Banners#
Banner rectangles are in window pixels. Drop a ZokoBanner node (a Control) where the banner should go; it reports its on-screen rectangle (accounting for stretch mode), requests on _ready, and clears itself when it leaves the tree.
| Property | Meaning |
|---|---|
container_id |
Banner id, default zoko-banner. |
size_mode |
responsive (largest size that fits) or one of 728x90, 300x250, 320x50, 468x60, 320x100. |
request_on_ready |
Request automatically in _ready. |
show_simulator_placeholder |
Draw a placeholder rectangle while the simulator answers. |
By hand: yield(ZokoGames.request_responsive_banner_async("menu", $BannerSlot.get_global_rect()), "completed"). Request banners on menu screens only.
Purchases#
func buy_first_item() -> void:
if not ZokoGames.is_store_available:
return
var catalog = yield(ZokoGames.store_get_catalog_items_async(), "completed")
if not catalog.ok or catalog.result.empty():
return
var bought = yield(ZokoGames.store_buy_item_async(catalog.result[0].sku), "completed")
if ZokoGames.has_error_code(bought, "purchaseCancelled"):
return
var token = yield(ZokoGames.store_get_purchase_token_async(), "completed") # send to your server and verify thereVerify ownership on your server (see in-game purchases). examples/zoko_store.gd is the full flow.
HTML5 export settings that matter#
- Custom HTML Shell:
res://addons/zokogames/export/zokogames_shell.html, as above. The canvas fills the frame, so use Canvas Resize PolicyAdaptiveand, in Project Settings > Display > Window > Stretch, a Mode of2dorviewportwith aspectexpandorkeep. - Threads. Godot 3 has no threaded web export, so there is nothing to untick. Game pages are not cross-origin isolated, so leave any
SharedArrayBufferoption off if your build shows one. - GDNative. Off. Native libraries do not run in web builds unless you ship a web-compatible one. Export With Debug: off for the uploaded build.
- Focus Canvas on Start: on. Experimental Virtual Keyboard: on if the game has text input on phones.
- File names. Export to a file named
index.html: the portal needsindex.htmlat the archive root, and the export names its other files after it:index.js,index.wasm,index.pck. Do not rename them to.bror.gz: the engine requests the plain names. - Texture compression. Enable VRAM compression for both desktop (S3TC) and mobile (ETC2) so every browser has a format.
- Size. Use a custom export template with unused modules disabled and keep the
.pcksmall. Limits: 1,500 files, 250 MB unpacked, about 50 MB initial download (20 MB for mobile). - Memory. Mobile browsers have a small heap; load levels with
ResourceLoader.load_interactivein slices rather than all textures up front, and cap resolution on phones, see mobile. - Audio unlock. Browsers keep audio suspended until the first click or key press. Show a "click to play" screen and start music from that input, not in
_ready. - Fullscreen. Use the fullscreen button in the portal's frame bar;
OS.window_fullscreen = truefullscreens your canvas only, so do not add a competing button. - Loading. The shell already reports the engine download and calls
loadingStopwhen the engine has started. For a longer in-game loading screen callZokoGames.loading_start(),loading_progress(percent)andloading_stop()yourself.
Upload: Project > Export, select the HTML5 preset, click Export Project..., and save into an empty folder with the file name index.html. Zip the folder contents so index.html is at the archive root, upload it in the developer console, and run the Preview tool first.
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("midgame")); the only other type is rewarded. Call ZokoGames.gameplay_start() when the player takes control: the first midgame ad needs it (or 30 seconds of visible page time), and in local mode a midgame request before that fails with adCooldown. Rewarded ads are not held back by this. Details: ads reference and ads guide.
Test locally#
- In the editor or a desktop run
ZokoGames.is_simulatedis true. Tune the simulator under Project Settings > zokogames/simulator:ad_behaviour(fill,no_fill,error),ad_duration_seconds,adblock,disabled,account_available,logged_in,username,user_id,friend_count,mute_audio,disable_chat,offline,store_availableandverbose. Cloud save is inuser://zoko_sim_data.json, the simulated inventory inuser://zoko_sim_inventory.json. The simulator does not enforce the three-minute midgame cooldown. - An HTML5 export on
localhost. Serve the export folder from a local web server (openingindex.htmlfrom disk does not work for WebAssembly). The bridge exists, sois_simulatedis false and the JavaScript SDK runs its own local mode. - Then open the Preview tool with your local address and watch the checklist tick.
Known pitfalls#
sdkNotLoaded. The page has no SDK script tag; use the custom shell.ZokoGamesautoload missing. The plugin is not enabled.- Calls fail with
sdkNotInitialized.yield(ZokoGames.init_async(), "completed")first. unsupportedEngine. You are running this addon on Godot 4; use the Godot 4 addon.- A
yieldnever returns. Ayieldin a function that is freed first (a scene change) is dropped; keep the waiting code in a node that stays, or use the callback form. - Works in the editor, not in the browser. Open the browser console and check that
window.ZokoBridgeexists (the shell defines it). - Game stays paused or muted after an ad. Something else changed
get_tree().pausedor the Master bus during the ad. Setpause_game_during_adsormute_audio_during_adstofalseand handlead_started,ad_finishedandad_erroryourself. Do not useCONNECT_ONESHOTonad_started: when an ad fails, it never fires. - Banners never show. The
ZokoBannernode needs a size and must be visible. user://saves are not in the cloud. Usedata_set_item, or the IndexedDB mirror above.
Chat reports and screenshots#
ZokoGames.report_chat({"reportedName": "Trixie", "message": "buy gold", "reason": "spam"}, callback) (or report_chat_async) sends a chat report. ZokoGames.set_screenshot_provider(funcref) replaces the default viewport capture (registered at init after frame_post_draw), and clear_screenshot_provider() removes yours. The editor simulator accepts both.
Next#
- Check your build against the build validation rules and the launch checklist.
- Upload and publish: submission walkthrough.
- Godot 4 projects: Godot. Other engines and shared rules: engines overview.