High scores that stick around, a "Continue" button, a game that remembers you muted the music. Save data is what turns a game into something people come back to.
Saving works on CraftNova. This guide shows how to get an AI to add it, and what you should know about how saving works here.
What you can save
- High scores and best times: beating your own record is a great reason to play one more round
- Progress: cleared stages, levels, items in the inventory
- Settings: sound on or off, difficulty, language
- Collections and achievements: characters collected, goals reached
What to ask the AI
Saving uses localStorage, a small storage area built into every browser. You don't need to know the details. A request like this is enough:
Add save data to this game.
- Save the high score and cleared stages to localStorage
- Store everything under one key as JSON
- If the save can't be read, start a fresh game instead of breaking
- Add a "Delete save data" button to the title screenThe "Game creation guidelines" on the posting page also describe how saving works, so give the AI the guidelines first for the best results.
What the code usually looks like
You don't need to understand every line, but it's roughly this:
// Save
const save = { highScore: 1200, clearedStage: 3 };
localStorage.setItem('mygame-save', JSON.stringify(save));
// Load (start fresh if it can't be read)
let data = { highScore: 0, clearedStage: 0 };
try {
data = JSON.parse(localStorage.getItem('mygame-save')) || data;
} catch (e) {}How saving works on CraftNova
Games on CraftNova run inside a protected box that keeps players safe (see How CraftNova keeps games safe to play). Inside that box, the browser's storage normally isn't available.
So CraftNova steps in: when a game writes to localStorage, CraftNova stores the data on the game's behalf and hands it back the next time the game opens. As a creator, you just use localStorage the normal way.
Things to know
Saves live on one device and one browser
Save data is stored in the player's browser, so progress on a phone won't show up on a PC. Clearing the browser's site data deletes saves too, and saves made in a private or incognito window disappear when the window closes.
About 1 MB per game
1 MB is far more than you need for scores and progress. But if a game tries to save images or huge logs, it can go over the limit and stop saving. Save only the numbers and text you really need.
Only localStorage is supported
Other storage methods, like IndexedDB or cookies, don't work on CraftNova. If the AI used one of them, ask it to "save with localStorage instead."
Saves survive game updates
When you replace your game's HTML from My page, players keep their saves. If you change the shape of the save data a lot, make sure old saves can still be loaded without breaking. Asking the AI to "keep it working even if a save from an older version exists" covers this.
How to check that saving works
- Post the game as Private (no one else can see it)
- Open it on CraftNova and play a little to set a score or make progress
- Reload the page, or leave and come back to the game
- If your record is still there, it works. Switch the game to Public
Summary
- Games on CraftNova can save with
localStorage - Ask the AI to "save to localStorage under one key as JSON"
- Saves stay on one device and browser, with about 1 MB per game
- A "Delete save data" button is a nice touch for players
For the full posting walkthrough, see How to post a game.