Construct 3
Call the SDK from your event sheets with script blocks, and add the SDK line when exporting for the web.
1. Call the SDK from your events
In the event where gameplay starts, right-click → Add script and write:
if (window.HGSDK) HGSDK.gameplayStart();
In the event where the run ends. The score line is optional: only if your game has a score (for example, the global variable Score).
if (window.HGSDK) HGSDK.sendScore(runtime.globalVars.Score); // optional
if (window.HGSDK) HGSDK.gameplayStop();
If your game has a pause menu:
if (window.HGSDK) HGSDK.gameplayStop(); // when opening your pause menu
if (window.HGSDK) HGSDK.gameplayStart(); // when closing it
if (window.HGSDK) avoids errors when you test the game in Construct's preview, where the SDK isn't loaded.
2. Export for the web
- Menu → Project → Export and choose Web (HTML5).
- Open the exported
index.htmland add the SDK line inside<head>, before any other script:
<script src="/sdk/v1/hg-sdk.js"></script>
Construct generates a new index.html on every export: repeat this step each time.
3. Ads (optional)
Your game doesn't load ads by itself: it asks the website and the website shows them on top, freezing and muting the game meanwhile. There are two kinds: break (between runs) and reward (the player chooses to watch it in exchange for something in the game). Don't report that gameplay stops or continues because of an ad: the SDK freezes and resumes your game on its own.
// Script block: ad the player chooses to watch
// when they ask to revive
const ad = window.HGSDK ? HGSDK.showAd({ type: "reward", name: "revive" }) : Promise.resolve({ rewarded: false });
ad.then(function (r) {
runtime.callFunction(r.rewarded ? "Revive" : "GameOver");
});
// Another script block, at another moment: to double their coins
const ad = window.HGSDK ? HGSDK.showAd({ type: "reward", name: "double_coins" }) : Promise.resolve({ rewarded: false });
ad.then(function (r) {
if (r.rewarded) runtime.globalVars.Coins *= 2;
});
// Script block: ad between runs, never before the first one
if (window.HGSDK && runtime.globalVars.Runs > 0) HGSDK.showAd({ type: "break" });
runtime.globalVars.Runs++;
runtime.callFunction("StartGame");
Several rewards: give each one its own name, a short label (up to 40 characters) that says which reward it is. Each script block receives the answer of its own ad in its then, so each reward handles its own result.
A reward can come back without an ad at any moment (none available or ads switched off): your game has to keep working. And a reward never gives score — revives, continues, extra lives or skins are fine.
4. Recommended settings
- Use worker: No, in Project Properties → Advanced: the SDK only works when the game runs on the page, not in a worker.
- Portrait project size (for example 720 × 1280) and Fullscreen mode: Scale outer to fit any screen.
- No start screen of your own: the website shows the cover. Start the game with the first tap anywhere.
- Don't save high scores with Local Storage: if your game has a score, the website saves the best of each signed-in player with
sendScore. - Sound: the SDK pauses and mutes your game's audio on its own, following the website's pause and sound button.
5. Test it
Upload the exported folder (or its .zip) in Upload game and tap 🧪 Test before submitting. More details in Test and publish.
HypercasualGaming