Skip to main content

Storage

Overview

The module allows working with local and cloud storage of platforms.

Types of storage:

  • platform FREE - Platform's cloud storage + local storages (maximum replication).
    • Yandex Games
    • CrazyGames
    • Platforms without support
    • GamePix
    • GameDistribution
    • GameMonetize
    • OK Games
    • SmartMarket
    • VK Games
    • VK Play
    • WG Playground
    • Kongregate
    • PlayDeck
    • Google Play
    • Telegram
    • beeline
    • Fotostrana
    • Y8
    • Android (alternative stores)
    • Web (custom site)
  • local FREE - Local storages, simultaneous saving in multiple types of local storages for reliability without loss of progress on iOS.
    • LocalStorage - standard local storage.
    • IndexedDB - browser database.
    • SafeStorage - safe storage provided by the platform.
      • Yandex Games
      • GamePix
      • CrazyGames
      • Web (custom site)
      • Platforms without support
      • GameDistribution
      • GameMonetize
      • OK Games
      • SmartMarket
      • VK Games
      • VK Play
      • WG Playground
      • Kongregate
      • PlayDeck
      • Google Play
      • Telegram
      • beeline
      • Fotostrana
      • Y8
      • Android (alternative stores)
  • You can switch between storage types at any time. Default value - platform.

    // Set storage type - platform's cloud storage + local storages
    gp.storage.setStorage('platform');

    // Set storage type - local storages
    gp.storage.setStorage('local');

    Contextual Storage

    FREE

    By default, all data is stored in the player's context. This allows storing different data for different players and platforms.

    Context consists of:

    • Project ID
    • Platform Type
    • Test / Live site version
    • Player ID on the platform

    This way, we can separate data for different platforms, even using the same domain. And separate this data among players. You can store guest data separately from authorized player data.

    With the get and set methods, you default to accessing data in the player's context. You can store any data types, we automatically convert them to the required format if the storage requires it.

    tip

    The method is asynchronous. Not all storages can set data instantly. Some, for example, cloud or IndexedDB, do it with a delay, so we return a promise or send an event when the data is set.

    Set Value

    // Set value
    await gp.storage.set('key', 'value');
    // Set number
    await gp.storage.set('gold', 1000);
    // Set boolean value
    await gp.storage.set('vip', true);

    // Set any data type
    await gp.storage.set('progress', {
    class: 'warrior',
    level: 5,
    gold: 1000,
    missions: [1, 5, 8],
    });

    Events on setting value

    // Value set
    gp.storage.on('set', ({ key, value }) => {});

    Get Value

    Getting values is also asynchronous.

    tip

    If there is no data, the storage will return null.

    // Get value
    const value = await gp.storage.get('key');
    // Get number
    const gold = await gp.storage.get('gold');
    // Get boolean value
    const vip = await gp.storage.get('vip');

    // Get any data type
    const progress = await gp.storage.get('progress');
    // progress.class
    // progress.missions[0]

    Events on getting value

    // Value retrieved
    gp.storage.on('get', ({ key, value }) => {});

    Global Storage

    FREE

    You can set data regardless of the player's context, in the global scope. This way, you can set a value for all profiles or transfer data between profiles.

    Set Value

    // Set value
    await gp.storage.setGlobal('key', 'value');
    // Set number
    await gp.storage.setGlobal('gold', 1000);
    // Set boolean value
    await gp.storage.setGlobal('vip', true);

    // Set any data type
    await gp.storage.setGlobal('progress', {
    class: 'warrior',
    level: 5,
    gold: 1000,
    missions: [1, 5, 8],
    });

    Events on setting value

    // Value set
    gp.storage.on('set:global', ({ key, value }) => {});

    Get Value

    Getting values is also asynchronous.

    tip

    If there is no data, the storage will return null.

    // Get value
    const value = await gp.storage.getGlobal('key');
    // Get number
    const gold = await gp.storage.getGlobal('gold');
    // Get boolean value
    const vip = await gp.storage.getGlobal('vip');

    // Get any data type
    const progress = await gp.storage.getGlobal('progress');
    // progress.class
    // progress.missions[0]

    Events on getting value

    // Value retrieved
    gp.storage.on('get:global', ({ key, value }) => {});

    Stay in Touch

    Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.

    GamePush Community Telegram: @gs_community.

    For your suggestions e-mail: [email protected]

    We Wish you Success!