Skip to content

Save data

AI Summary

A short gist of this page, generated for you.

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

saveProgress() and loadProgress() keep a player's progress on their Funox account, so it follows them to any device.

#How saving behaves

Situation saveProgress() loadProgress()
On Funox, player logged in Saved to the player's account Returns the saved data
On Funox, guest player Rejects with NOT_AUTHENTICATED Returns null
Standalone mode Saved to the browser's localStorage Returns the browser's copy

#Limits

  • Up to 100 KB per save, measured as JSON. Larger data is rejected with DATA_TOO_LARGE.
  • The data must be a plain object. Anything else is rejected with INVALID_DATA.

#saveProgress(data)

Saves the player's progress. Keep everything in one object.

javascript
var saveData = {
  level: 5,
  score: 12400,
  inventory: ['sword', 'shield'],
  settings: { sfx: true, music: false }
};

FunOxSDK.saveProgress(saveData)
  .then(function (result) {
    console.log('Saved at', result.timestamp);
  })
  .catch(function (err) {
    if (err.code === 'NOT_AUTHENTICATED') {
      saveLocally(saveData); // guest player
    }
  });

It resolves with { saved: true, timestamp }.

#loadProgress()

Resolves with the saved object, or null if there is no save or the player is a guest.

javascript
FunOxSDK.loadProgress().then(function (data) {
  if (data) {
    applyLoadedData(data); // resume from the save
  } else {
    startNewGame();
  }
});

#Guests

Guests cannot save to the cloud, so keep a local copy for them:

javascript
function saveLocally(data) {
  try { localStorage.setItem('my_game_save', JSON.stringify(data)); }
  catch (e) { /* private browsing: ignore */ }
}

function loadLocally() {
  try { return JSON.parse(localStorage.getItem('my_game_save')); }
  catch (e) { return null; }
}

function save(data) {
  saveLocally(data);
  FunOxSDK.saveProgress(data).catch(function () { /* guest or offline */ });
}

function load() {
  return FunOxSDK.loadProgress()
    .catch(function () { return null; })
    .then(function (cloud) { return cloud || loadLocally(); });
}

Saving both ways also protects the player if a cloud save fails.

#When to save

  • After each level, round or purchase — not on every frame.
  • Before an ad break and when the game is paused.
  • Do not rely on saving when the tab closes; the request may not finish.

#Errors

Code Cause What to do
NOT_AUTHENTICATED The player is a guest Save locally
DATA_TOO_LARGE The save is over 100 KB Store less
INVALID_DATA The data is not a plain object Pass an object, not a string
SAVE_FAILED The save could not be stored Keep the data and retry later
LOAD_FAILED The save could not be read Retry, or fall back to the local copy