Construct 3: the InstaPlay SDK for Construct games
For Construct 3, InstaPlay ships the project script instaplay-c3.js 1.3.0 (the whole SDK 1.4,
including the player token for your own server, ads and sign-in from the game). It loads the SDK /_ip/sdk/v1.js, calls
InstaPlay.init() on start, sends loading.progress(1) before the project starts (Construct does not
give the script real loading progress), ready after the first layout, and turns portal events into
global variables and event sheet functions.
Mute the sound yourself. The script does not touch audio: autoPause only stops
runtime.timeScale. The catalog requires silence on pause and when the portal sound is off
(events): in the InstaPlay_OnPause and InstaPlay_OnMute functions turn
the Audio plugin volume down (for example, Audio → Set master volume −100 dB), and restore it in
InstaPlay_OnResume and InstaPlay_OnUnmute.
Setup
- Download the archive: instaplay-construct-1.3.0.zip
(it contains
instaplay-c3.js, README and CHANGELOG; size and sha256 are in manifest.json). Project → Scripts → Import scripts →instaplay-c3.jsfrom the archive; in the script properties set Purpose: Main script (or paste its contents into your existing main script). - Project Properties → Advanced → Use worker: No — the SDK talks to the portal via
window.parent, which a worker does not have. - Project Properties → Offline support: off — Service Workers are forbidden on the games domain
(the script gets
403, game network) and would get in the way of build updates anyway. - Create the global variables you need (the script writes only the ones that exist in the project).
Global variables
| Variable | Type | What |
|---|---|---|
IP_Environment |
text | instaplay / local / disabled |
IP_Locale |
text | ru / en, changes on a portal event |
IP_PlayerName |
text | player nickname |
IP_SaveData, IP_SaveVersion |
text, number | the last loaded save (JSON) and its version |
IP_Rank |
number | the all-time rank after submitScore |
IP_LeaderboardJson |
text | a leaderboard page (JSON) |
IP_Paused, IP_Muted |
number | 1 — paused or muted by the portal |
IP_LastError |
text | the last SDK error code |
IP_Session |
text | ok / none / local — whether there is a portal session (SDK 1.1) |
IP_Country |
text | the player's country (ISO 3166-1, DE) or empty (SDK 1.2) |
IP_Token |
text | the last player token after getToken (SDK 1.1) |
IP_ChangeReason |
text | login / logout / switch — why the player changes (SDK 1.1) |
IP_AdShown, IP_AdRewarded |
number | 1 — the interstitial was shown / the ad reward was earned (SDK 1.3) |
IP_AdReason |
text | the reason of the last ad call (no_fill, cooldown, declined…) or empty |
IP_AdGrant |
text | the signed reward for your server or empty (SDK 1.3) |
Event sheet functions (optional): InstaPlay_OnPause(reason), InstaPlay_OnResume,
InstaPlay_OnMute, InstaPlay_OnUnmute (the Audio volume goes here),
InstaPlay_OnLocaleChanged(locale), InstaPlay_OnSaveLoaded(key), InstaPlay_OnError(code),
InstaPlay_OnPlayerChanging(reason) (in ~1.5 s the portal restarts the game with another player —
send your data to your server), InstaPlay_OnToken(token), InstaPlay_OnAdDone(kind, ok, reason) — the ad outcome (kind:
interstitial / rewarded, ok: 1 / 0). If the portal is already paused or muted at
init, the script calls InstaPlay_OnPause / InstaPlay_OnMute right away.
Calls from the event sheet
In an event — the “Add script” action:
await InstaPlayC3.saveGet('progress') // → IP_SaveData, then the InstaPlay_OnSaveLoaded function
InstaPlayC3.saveSet('progress', JSON.stringify({ best: runtime.globalVars.Best }))
InstaPlayC3.gameplayStart()
InstaPlayC3.submitScore('main', runtime.globalVars.Score) // → IP_Rank
InstaPlayC3.levelCompleted('3', '{"stars":2}')
InstaPlayC3.event('shop_open')
All methods: ready, gameplayStart, gameplayStop, happyMoment, levelStarted, levelCompleted,
levelFailed, event, isSupported, serverTime, playerName, getToken (→ IP_Token and
InstaPlay_OnToken; outside the portal — not_supported; server-side check — player token), saveGet,
saveSet(key, json, immediate), saveRemove, saveFlush, submitScore,
leaderboardGet(board, period, around, limit), adsInterstitial(placement, moment),
adsRewarded(placement), adsAvailable(type), login(). No method throws: the promise resolves to
null, and the code goes to IP_LastError and the InstaPlay_OnError function.
Sign-in from the game (SDK 1.4, script 1.3.0). await InstaPlayC3.login() opens the portal sign-in
window over the game; the outcome goes to IP_LoginStatus and the InstaPlay_OnLogin(status) function
(signed_in, already_signed_in, cancelled or an error code), the player kind — to IP_PlayerKind.
Show the “Save progress” button to a guest when isSupported('login') and call login() from a script
block right in the press event (On clicked, On tap) — otherwise gesture_required. The example, the
stub (config.stubLogin) and all errors are in the script README (inside the
instaplay-construct-1.3.0.zip archive); rules and
patterns — Player and sign-in.
InstaPlayC3.config.autoReady (true by default) sends ready after the first layout starts;
autoPause sets runtime.timeScale = 0 on a portal pause. In the Construct preview, where there is no
SDK, a stub runs: saves and the score in memory.
Ads
Ads are shown by the portal; the game only asks (ads in your game):
// Level cleared: gameplayStop first (no interstitial during play).
await InstaPlayC3.gameplayStop()
await InstaPlayC3.adsInterstitial('level_end', 'next') // → IP_AdShown, InstaPlay_OnAdDone
// The “+1 life for an ad” button — only when the portal is ready to show a rewarded ad:
if (await InstaPlayC3.adsAvailable('rewarded')) runtime.globalVars.ShowLifeButton = 1
// When the player presses the button:
if (await InstaPlayC3.adsRewarded('extra_life')) runtime.globalVars.Lives += 1 // IP_AdGrant — to the server
Normal outcomes (no ad, a cooldown, the player declining) are not errors: the promise gives false, the
reason goes to IP_AdReason. InstaPlay_OnAdDone(kind, ok, reason) is called after every ad, also on a
protocol error (then reason is the error code and the promise gives null). During an ad
InstaPlay_OnPause("ad") and InstaPlay_OnMute arrive — mute Audio there as for any pause.
IP_AdGrant is the signed reward for your server (reward verification); empty — unsigned
(preview, stub).
If the SDK did not load, ads are a stub: InstaPlayC3.config.stubAds = { outcome, seconds }, outcome
— completed (shown, the reward is unsigned), no_fill, dismissed (closed a rewarded ad early),
declined (declined in the card), disabled (no ads). By default (outcome: null) it is completed
only in the Construct preview (preview.construct.net, localhost) and disabled everywhere else
(third-party hosting, a file, an SDK load failure), as the SDK outside the portal. “Shown” sends a pause and mute for seconds
seconds; an interstitial between gameplayStart and gameplayStop gets gameplay_active.
Not in the script
saves.getMany, saves.clear, a custom saves.onConflict handler (the SDK default applies),
analytics.flush and the visibility event — if needed, call window.InstaPlay directly from a
script block (SDK). There is no .c3addon add-on yet.
Export and upload
Export as Web (HTML5). Check the folder with instaplay test ./export (CLI), then zip its
contents (index.html at the zip root) and upload it in the dashboard (Uploading a build).