Dein Spiel
How to save player progress in an HTML5 game
Add the klyo SDK to index.html, call klyo.save.get when the game starts and klyo.save.set after each meaningful change. Progress is stored on the klyo server, follows a signed in player to every device, and you can test it in the studio preview before you publish.
Bevor du loslegst
- A browser game (plain JavaScript, Godot, Unity, GameMaker or any engine that exports to the web) and access to its index.html.
- The game state as an object that fits in 64 KB, for example level, coins and settings.
- No server or database on your side: the SDK and the klyo page do the rest.
Schritt für Schritt
SDK einbinden
Put this line in index.html before your own script:
<script src="https://games.klyo.pl/sdk/klyo-gry-sdk.js"></script>. An engine that exports to the web calls the same functions through its own way of calling JavaScript from the game.Load progress at start
Call
klyo.save.get(callback)once when the game starts. Whenz.okis true andz.datais set, restore the game fromz.data.z.cloudis true when the klyo server answered, andz.reasonsays why the data comes only from the browser.Save after meaningful changes
Call
klyo.save.set(state, callback)after a level, a purchase or a change of settings. The SDK keeps a copy in the browser and merges saves that come faster than every 2 seconds into one, so you do not need a timer of your own.Test it in the studio preview
Upload the package and play in the preview window. Saves go to the preview cloud that only you can see, and the answer has
o.cloudando.previewset to true. Callklyo.save.getagain, or open the preview again, and the same data comes back withz.sourceequal to "chmura".Publish the game
After release every player saves into a slot of their own: a signed in player keeps progress on every device, a guest keeps it in this browser. Your preview save disappears together with the preview.
Wenn etwas nicht klappt
The answer says the data is local
z.reason tells you why. bez-strony: the game runs outside klyo (straight from a file or on another site), so progress stays in the browser. bez-serwera: there was no connection, and the SDK sends the copy again later. pusto-w-chmurze: the cloud had nothing yet, so the game got the browser copy and the SDK sent it to the cloud.
My code waits and then gives up
The answer always arrives, at the latest after 8 seconds, and on klyo it arrives at once. Remove a shorter timeout of your own and start the game from the browser copy while the cloud answers.
A save is rejected with rozmiar
The state is larger than 64 KB once encoded. Save only what you need to restore the game, not the whole scene.
Häufige Fragen
Does the player need an account to keep progress?
No. Without an account progress belongs to this browser. With an account it follows the player to every device, and the copy saved in this browser before signing in moves to the account.
What happens when two devices save at the same time?
The latest save in the cloud wins. A browser copy that the server has not confirmed yet goes up only when no other device saved in the meantime, so an older copy never overwrites newer progress.
Do players see my test saves from the preview?
No. The preview has a slot of its own that only you and klyo moderators can open, and it is deleted together with the preview.