Storage Methods

The storage service provides developers the ability to store and retrieve game data.


These methods do not implement any kind of locking mechanism to handle concurrent/asynchronous requests. The latest save call will always persist over any previous calls.

saveGame(key, value)

Stores or updates the object for the given key.

The value will be serialized as JSON using JSON.stringify() when saved and will later be deserialized using JSON.parse() when retrieved using the retrieveGame() method.

When attempting to increment or decrement keys using the incrementGame() or decrementGame() methods, the key's initial value should be an integer.

// A complex object with multiple parameters
ag.saveGame('stats_level_1', {
  time: 501,
  score: 32,
  duration: 72
}).then(function(response) {
    // response == {
    //   key:'stats_level_1',
    //   success:1 // 1 saved, 0 failed
    // }

// A simple integer value which could be incremented/decremented later
ag.saveGame('cash', 1000)
  .then(function(response) {
    // response == {
    //  key: 'cash',
    //  success: 1
    // }


Retrieves the specified object tied to the key and returns it.

// A complex object with multiple parameters
ag.retrieveGame('stats_level_1').then(function(response) {
  // response[key] will be the retrieved value
  var data = response.stats_level_1;
  // { "time": 501, "score": 31, "duration": 72 }

// Simple integer value
ag.retrieveGame('cash').then(function(response) {
  var data =; // 1000


Deletes the specified game data for the key.

ag.eraseGame('stats_level_1').then(function(response) {
  // response[key] will be a string with the value "deleted"

incrementGame(key, quantity = 1)

Increments the specified key by the quantity supplied (defaults to 1). If the key does not exist, it will default to a value of zero and then will be incremented by the quantity. Increments may only be performed by integer values (no floats/doubles/decimals) and must be greater than zero. To subtract from a value, use the decrementGame() method instead.

// Assuming we previously called ag.saveGame('cash', 1000)
ag.incrementGame('cash', 100).then(function(response) {
  // response[key] will contain the incremented value saved 
  // ie, = 1100

decrementGame(key, quantity = 1)

This method is the reverse of the incrementGame() method. It decrements by the quantity supplied (defaulting to 1).

// Assuming we previously called ag.saveGame('cash', 1000)
ag.decrementGame('cash', 25).then(function(response) {
  // response[key] will contain the decremented value saved
  // ie, = 975