Skip to contentGo to cookie choices
Skip to docs navigation

Copy-paste example: one index.html

https://docs.zokogames.com/getting-started/one-file-example

This page is one file you can paste, run, zip and upload without changing anything. It is the smallest game that uses every part of the SDK a first submission needs: init, the loading signals, gameplayStart and gameplayStop, one rewarded ad with a fallback, and a save. It takes about 10 minutes. The longer, two-file tutorial with a midgame ad and happytime is Build a minimal game in 15 minutes; the numbered path that includes the console is Your first game live in 30 minutes.

1. Save this as index.html#

Make an empty folder named coin-tap and save the file inside it as index.html. Nothing else is needed.

HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Coin Tap</title>
  <!-- The real SDK script. It must come before your own code. -->
  <script src="https://sdk.zokogames.com/zokogames-sdk-v1.js"></script>
  <style>
    html, body { margin: 0; height: 100%; background: #14161f; color: #fff; font: 18px sans-serif; text-align: center; }
    main { padding-top: 12vh; }
    button { font: inherit; padding: 12px 24px; margin: 6px; }
    #coin { width: 120px; height: 120px; border-radius: 50%; border: 0; background: #ffc531; touch-action: manipulation; }
    [hidden] { display: none !important; }
  </style>
</head>
<body>
  <main>
    <h1>Coin Tap</h1>
    <p>Score <b id="score">0</b> | Time <b id="time">10</b> | Best <b id="best">0</b></p>
    <p><button id="coin" aria-label="Coin" hidden></button></p>
    <p id="msg">Loading...</p>
    <button id="play" disabled>Play</button>
    <button id="bonus" hidden>Watch an ad for +5 seconds</button>
  </main>
  <script>
    var SDK = window.ZokoGames && window.ZokoGames.SDK; // undefined if the script was blocked
    var $ = function (id) { return document.getElementById(id); };
    var usable = false, running = false, score = 0, best = 0, left = 10, extra = 0, timer = 0;

    // Every SDK call goes through here: if the SDK is missing, disabled or a call fails, the game still runs.
    // SDK errors are plain { code, message } objects, not Error instances.
    function zoko(call) {
      if (!usable) return Promise.resolve(undefined);
      return Promise.resolve().then(call).catch(function (e) {
        console.warn("SDK:", e && e.code, e && e.message);
      });
    }

    function boot() {
      var ready = SDK ? SDK.init() : Promise.resolve(); // init() never rejects
      return ready
        .then(function () { usable = !!SDK && SDK.environment !== "disabled"; })
        .then(function () { return zoko(function () { return SDK.game.loadingStart(); }); })
        .then(function () {
          if (usable) { // saves are synchronous and throw on error, so keep them inside try
            try { best = Number(SDK.data.getItem("best")) || 0; } catch (e) { console.warn("SDK:", e.code); }
          }
          $("best").textContent = best;
          $("bonus").hidden = !usable;
          return zoko(function () { return SDK.game.loadingStop(); }); // the first screen is ready
        })
        .then(function () { $("msg").textContent = "Tap the coin as often as you can."; $("play").disabled = false; });
    }

    function setRunning(on) {
      if (on === running) return;
      running = on;
      clearInterval(timer);
      if (on) timer = setInterval(tick, 1000);
      zoko(function () { return on ? SDK.game.gameplayStart() : SDK.game.gameplayStop(); });
    }

    function startRound() {
      score = 0; left = 10 + extra; extra = 0;
      $("play").hidden = $("bonus").hidden = true;
      $("coin").hidden = false;
      $("msg").textContent = "";
      render();
      setRunning(true); // input is live now: gameplayStart
    }

    function tick() { left -= 1; render(); if (left <= 0) endRound(); }

    function endRound() {
      setRunning(false); // round over: gameplayStop
      $("coin").hidden = true;
      $("play").hidden = false;
      $("bonus").hidden = !usable;
      $("msg").textContent = "Round over: " + score;
      if (score > best) {
        best = score;
        $("best").textContent = best;
        if (usable) {
          try { SDK.data.setItem("best", String(best)); } catch (e) { console.warn("SDK:", e.code); }
        }
      }
    }

    // Rewarded ad with a fallback: the reward is granted only when the ad finished; every other outcome just carries on.
    $("bonus").addEventListener("click", function () {
      var finished = false;
      $("bonus").disabled = $("play").disabled = true;
      zoko(function () {
        return SDK.ad.requestAd("rewarded", {
          adFinished: function () { finished = true; },
          adError: function (e) { console.info("No ad:", e.code); } // adsDisabled before full launch, unfilled, adblock...
        });
      }).then(function () {
        $("bonus").disabled = $("play").disabled = false;
        if (finished) { extra = 5; $("msg").textContent = "+5 seconds next round."; }
        else { $("msg").textContent = "No ad right now. Play on."; } // the fallback
      });
    });

    $("coin").addEventListener("pointerdown", function (e) { e.preventDefault(); if (running) { score += 1; render(); } });
    $("play").addEventListener("click", startRound);
    window.addEventListener("blur", function () { if (running) setRunning(false); });  // pause when focus leaves
    window.addEventListener("focus", function () { if (!$("coin").hidden) setRunning(true); });
    function render() { $("score").textContent = score; $("time").textContent = left; }
    boot();
  </script>
</body>
</html>

The game keeps working when the SDK is blocked or SDK.environment is "disabled": zoko() skips every call and the buttons that need the portal stay hidden. The SDK script URL is the real one, https://sdk.zokogames.com/zokogames-sdk-v1.js; do not copy the file into your build.

2. What each part does#

Part SDK call Why it is there
Script tag in <head> none Defines window.ZokoGames.SDK. The upload report warns no_sdk without it.
boot() SDK.init(), then SDK.environment init() is required first and never rejects; a failure shows as "disabled".
Loading SDK.game.loadingStart(), SDK.game.loadingStop() Separates load time from play time. Call loadingStop when the first screen is playable.
Play and the end of the round SDK.game.gameplayStart(), SDK.game.gameplayStop() gameplayStart is the first call the Preview checklist waits for (within 20 seconds of load); gameplayStop closes the round and also runs when the window loses focus.
Bonus button SDK.ad.requestAd("rewarded", { adFinished, adError }) Reward only in adFinished. In basic launch the portal answers adsDisabled, so the fallback branch is the one you will see first.
Best score SDK.data.getItem, SDK.data.setItem Synchronous and string-only; they throw { code, message } on error, so they sit in try.

3. Run it on your machine#

On localhost the SDK answers every call itself: no portal, no account. Serve the folder over HTTP (file:// does not count as local), then open the address with ?sdk_debug=true.

Bash
cd coin-tap
npx http-server . -p 8080
# or, without Node.js:
python3 -m http.server 8080
# open http://localhost:8080/?sdk_debug=true

You should see one [ZokoGames SDK] Local mode: ... line when the page opens, [ZokoGames SDK] call game.loadingStart and call game.loadingStop before Play becomes active, then call game.gameplayStart when you press Play and call game.gameplayStop after ten seconds. Pressing Watch an ad for +5 seconds covers the page for three seconds with a placeholder labelled Local ad (rewarded), then the message changes to "+5 seconds next round." Typing ZokoGames.SDK.environment in the console prints "local". Add &ad_response=unfilled to the address to see the fallback ("No ad right now. Play on."), and &ad_response=adsDisabled to see what basic launch looks like. Every switch is in testing.

Then open the Preview tool, type http://localhost:8080/ and press Load game, play one round and press the bonus button: the checklist ticks SDK initialised (init called), loadingStop called, gameplayStart called, gameplayStop called, Rewarded ad requested and Data module used, and the timing line shows the time to the first gameplayStart under 20 s. Items for midgame ads and happytime stay grey, which does not block a first submission.

4. Zip it#

index.html must be at the root of the archive. One top-level folder is also accepted, and system files such as __MACOSX and .DS_Store are ignored.

System Command or action Result
macOS or Linux cd coin-tap && zip ../coin-tap.zip index.html coin-tap.zip next to the folder
Windows 10 or 11 In the folder, run tar -a -c -f ..\coin-tap.zip index.html coin-tap.zip next to the folder
Any system, with a file manager Select the files inside the folder (not the folder), then compress them A zip with index.html at the root

Check it with unzip -l coin-tap.zip (macOS, Linux) or tar -tf coin-tap.zip (Windows): the list must show index.html and nothing in front of it. Older Windows PowerShell versions can write backslashes into zip entry names with Compress-Archive; the validator rejects those as unsafe_path, so use tar or the file manager.

5. Upload it#

Follow steps 6 and 7 of Your first game live in 30 minutes: drop coin-tap.zip on Drop your game zip here on the Build step. You should see "Build v1 passed validation and was published." with the SDK detected and no errors. The listing still needs your own description, controls, tags and covers before Submit for review.

Next steps#

Something unclear, wrong or missing on this page? Tell us through support · Test your game in the preview tool