User Data

Store and manage player data to enhance gameplay experience and retain progress.

There are two types of storage: local (local_storage) and internal (platform_internal). When writing to local storage, data is saved on the player's device. When writing to internal storage, data is saved on the platform's servers.

Default Storage Type

Identify the default storage type to understand where data is being saved (local or server).

Bridge.storage.default_type

Used automatically if no specific storage type is specified when working with data. Possible values: local_storage, platform_internal.

Support Check

Verify if the specified storage type is supported on the platform to ensure compatibility.

Bridge.storage.is_supported("local_storage")
Bridge.storage.is_supported("platform_internal")

# To use constants for convenience:
Bridge.storage.is_supported(Bridge.StorageType.LOCAL_STORAGE)
Bridge.storage.is_supported(Bridge.StorageType.PLATFORM_INTERNAL)

Availability Check

Check if the specified storage type is currently available for use to manage data storage effectively.

Bridge.storage.is_available("local_storage")
Bridge.storage.is_available("platform_internal")

# To use constants for convenience:
Bridge.storage.is_available(Bridge.StorageType.LOCAL_STORAGE)
Bridge.storage.is_available(Bridge.StorageType.PLATFORM_INTERNAL)

Load Data

Retrieve stored data based on a key or multiple keys to restore player progress or settings.

# Load data by key
func _ready():
    Bridge.storage.get("level", funcref(self, "_on_storage_get_completed"))

func _on_storage_get_completed(success, data):
    if success:
        if data != null:
            print(data)
        else:
            # No data for the key 'level'
            print("Data is null")

# Load data by multiple keys
func _ready():
    Bridge.storage.get(["level", "coins"], funcref(self, "_on_storage_get_completed"))

func _on_storage_get_completed(success, data):
    if success:
        if data[0] != null:
            print("Level: ", data[0])
        else:
            # No data for the key 'level'
            print("Level is null")

        if data[1] != null:
            print("Coins: ", data[1])
        else:
            # No data for the key 'coins'
            print("Coins is null")

# Load data from a specific storage type
Bridge.storage.get("level", funcref(self, "_on_storage_get_completed"), Bridge.StorageType.LOCAL_STORAGE)

Save Data

Save data to the specified storage with a key to retain player progress or settings.

# Save data by key
func _ready():
    Bridge.storage.set("level", "dungeon_123", funcref(self, "_on_storage_set_completed"))

func _on_storage_set_completed(success):
    print("On Storage Set Completed, success: ", success)

# Save data by multiple keys
Bridge.storage.set(["level", "is_tutorial_completed", "coins"], ["dungeon_123", true, 42], funcref(self, "_on_storage_set_completed"))

# Save data to a specific storage type
Bridge.storage.set("level", "dungeon_123", funcref(self, "_on_storage_set_completed"), Bridge.StorageType.LOCAL_STORAGE)

Delete Data

Remove data from the specified storage by key to manage player data and settings effectively.

# Delete data by key
func _ready():
    Bridge.storage.delete("level", funcref(self, "_on_storage_delete_completed"))

func _on_storage_delete_completed(success):
    print("On Storage Delete Completed, success: ", success)

# Delete data by multiple keys
Bridge.storage.delete(["level", "is_tutorial_completed", "coins"], funcref(self, "_on_storage_delete_completed"))

# Delete data from a specific storage type
Bridge.storage.delete("level", funcref(self, "_on_storage_delete_completed"), Bridge.StorageType.LOCAL_STORAGE)

If no specific storage type is passed as the third argument when working with data, the default storage type Bridge.storage.default_type is used.

Last updated