Online saving allows players to store their game data online, so they can start where they left off on different devices and websites. The APIs can save, retrieve, and delete small amounts of data like a game state. Data is limited to 50 Kb and API calls are blocked after 100 have been sent in 5 minutes.

Before Starting

To minmize the amount of API calls being made, combine data in an object using JSON. This will prevent a game from making many small API calls and hitting the 100 calls per a 5 minute limit.

Setting Data

var gameSave1 = {
	level: 31,
	health: 66,
	inventory: [
			['healthpotion', 9],
			['sword', 'beastmode']
	]
};

sdk.submitUserData('gameSave1', JSON.stringify(gameSave1));

The handleSDK function will receive a response with the type submit and data of {“status”:”ok”} or {“status”:”not saved”}.

Getting Data

sdk.retrieveUserData('gameSave1');

function handleSDK(e:Event) {
	if (sdk.type == 'retrieve') {
		if (sdk.data.hasOwnProperty('error') === false) {
			trace('key is '+sdk.data.key+' data is '+sdk.data.jsondata);
		} else {
			trace('Error: '+sdk.data.error);
		}
	}
}

Note that if there no data found for the gameSave1 key, an error of {“error”:”Key not found”} will be returned to handleSDK.

Clearing Data

sdk.removeUserData('gameSave1');

The handleSDK function will receive a response with the type delete and data of {“status”:”ok”}.

Important Notes

  • Minimize the amount of data that should be saved. Consider ways to compress data.
  • It’s better to have 1 bigger save rather than 5 smaller ones. Try to condense calls into a single one.
  • Avoid auto-saving using a timer. If you have no other choice, do it no more than once a minute.
  • Try to not exceed 30Kb. There is some headroom, but larger saves may get rejected by the API.
  • Know that saving too frequently may not succeed and should be retried after a few seconds.
  • In Flash, saving the same data 2 times in series will only send one submit call.