# 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.

{% hint style="warning" %}
If you need to call storage methods in a sequence, make sure you wait for previous call to finish, so there is no potential data collisions.&#x20;
{% endhint %}

{% hint style="warning" %}
Use TYPE\_ARRAY parameters for batch operations.&#x20;
{% endhint %}

#### Default Storage Type <a href="#default-storage-type" id="default-storage-type"></a>

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

```gdscript
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 <a href="#support-check" id="support-check"></a>

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

```gdscript
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 <a href="#availability-check" id="availability-check"></a>

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

```gdscript
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)
```

#### <img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2F9BooaofCI33U9Np5oeif%2FFrame%203%20(1).png?alt=media&#x26;token=0750b56a-a069-4759-bda9-29951f06cd30" alt="" data-size="line"> Load Data <a href="#load-data" id="load-data"></a>

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
# 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)
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
# Load data by key
func _ready():
    Bridge.storage.get("level", Callable(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"], Callable(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", Callable(self, "_on_storage_get_completed"), Bridge.StorageType.LOCAL_STORAGE)
```

{% endtab %}
{% endtabs %}

#### <img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2F9BooaofCI33U9Np5oeif%2FFrame%203%20(1).png?alt=media&#x26;token=0750b56a-a069-4759-bda9-29951f06cd30" alt="" data-size="line"> Save Data <a href="#save-data" id="save-data"></a>

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
# 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)
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
# Save data by key
func _ready():
    Bridge.storage.set("level", "dungeon_123", Callable(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], Callable(self, "_on_storage_set_completed"))

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

```

{% endtab %}
{% endtabs %}

#### Delete Data <a href="#delete-data" id="delete-data"></a>

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
# 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)
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
# Delete data by key
func _ready():
    Bridge.storage.delete("level", Callable(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"], Callable(self, "_on_storage_delete_completed"))

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

{% endtab %}
{% endtabs %}

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.playgama.com/playgama/sdk/engines/godot/user-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
