Skip to content

Construct

AI Summary

A short gist of this page, generated for you.

Powered by AI. Summaries can miss nuance — when in doubt, read the page.

Construct 3 projects call the SDK through the Browser object, which runs JavaScript on the page where the SDK lives.

#Install

  1. Add the Browser object to your project.
  2. Export your project as HTML5.
  3. Open the exported index.html and add the SDK inside <head>, before the other scripts:
html
<script src="https://funox.com/sdk/v1/funox-sdk.js"></script>

You need to add this line again each time you export.

#Initialize

On Start of layout of your first layout, add the action Browser → Execute JavaScript:

javascript
FunOxSDK.init();

#Gameplay signals

On Start of layout of your game layout (not the menu):

javascript
FunOxSDK.gameplayStart();

On End of layout, or when the game is over:

javascript
FunOxSDK.gameplayStop();

#Ad break

An ad takes time, so the event sheet needs to know when it has finished. Set a flag from JavaScript and check it from an event.

  1. At a natural break, pause your game (set the time scale to 0 and silence audio), then run Browser → Execute JavaScript:
javascript
window.funoxAdDone = false;
FunOxSDK.commercialBreak()
  .catch(function () {})
  .then(function () { window.funoxAdDone = true; });
  1. Add an event with the condition System → Compare two values:
text
Browser.ExecJS("window.funoxAdDone ? 1 : 0")  =  1
  1. In that event, run Execute JavaScript with window.funoxAdDone = false;, then resume the game.

A rewarded ad works the same way — store the result so the event sheet can read it:

javascript
window.funoxRewardEarned = -1; // -1 waiting, 0 no reward, 1 reward earned
FunOxSDK.rewardedBreak('extra_life')
  .then(function (result) { window.funoxRewardEarned = result.completed ? 1 : 0; })
  .catch(function () { window.funoxRewardEarned = 0; });

Grant the reward only when Browser.ExecJS("window.funoxRewardEarned") equals 1.

#Save data

javascript
FunOxSDK.saveProgress({ level: 5, score: 12400 }).catch(function () {});

To load, store the result where the event sheet can read it:

javascript
window.funoxSave = '';
FunOxSDK.loadProgress().then(function (data) {
  window.funoxSave = data ? JSON.stringify(data) : '{}';
});

Read it with Browser.ExecJS("window.funoxSave") once it is no longer empty, and parse it with the JSON object.

#Tips

  • Call gameplayStart() on the game layout, not on the loading or menu layout.
  • Run every SDK call through the Browser object. Script files that run in a worker cannot see FunOxSDK.
  • Check the result in the portal preview — the live feed shows each call as it happens.