# User Data

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

There are two types of storage: `LocalStorage` and `PlatformInternal`. 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 %}

#### Default Storage Type

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

```javascript
PlaygamaBridge.DefaultStorageType
```

Used automatically if a specific type is not specified when working with data. Possible values: `LocalStorage`, `PlatformInternal`.

#### Support Check

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

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2Fjssdaxx9MG3YCCmf3joI%2FScreenshot%202024-10-17%20at%206.19.41%E2%80%AFPM.png?alt=media&#x26;token=8a206c43-c22d-40e9-a9fa-92be0482c13c" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"is-storage-supported","objectClass":"PlaygamaBridge","parameters":{"storage-type":"local-storage"}}],"actions":[{"type":"comment","text":"local storage supported"}]},{"eventType":"block","conditions":[{"id":"is-storage-supported","objectClass":"PlaygamaBridge","parameters":{"storage-type":"platform-internal"}}],"actions":[{"type":"comment","text":"platform internal supported"}]}]}
```

</details>

Ensure the platform supports the required features and storage types for proper functionality.

#### Storage Accessibility Check

Check if the specified storage type is currently available for use to manage data storage effectively. Possible values: `true`, `false`.

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FhMQwpdKOOq1GV0u6SByL%2FScreenshot%202024-10-17%20at%206.21.51%E2%80%AFPM.png?alt=media&#x26;token=41d39874-181c-43e4-961b-e6b095ca0069" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"is-storage-available","objectClass":"PlaygamaBridge","parameters":{"storage-type":"local-storage"}}],"actions":[{"type":"comment","text":"local storage available"}]},{"eventType":"block","conditions":[{"id":"is-storage-available","objectClass":"PlaygamaBridge","parameters":{"storage-type":"platform-internal"}}],"actions":[{"type":"comment","text":"platform internal available"}]}]}
```

</details>

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

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

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FKRIPd9ZlfXYd9TTwT8FI%2FScreenshot%202024-10-17%20at%206.24.48%E2%80%AFPM.png?alt=media&#x26;token=2c0c329f-9b58-458b-994b-be5daa6d9017" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you need data in JSON format, use the `PlaygamaBridge.StorageDataAsJSON("key_1")` expression.
{% endhint %}

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-clicked","objectClass":"Button"}],"actions":[{"id":"append-storage-data-get-request","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_1\""}},{"id":"append-storage-data-get-request","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_2\""}},{"id":"send-storage-data-get-request","objectClass":"PlaygamaBridge","parameters":{"storage-type":"default"}}]},{"eventType":"block","conditions":[{"id":"on-storage-data-get-request-completed","objectClass":"PlaygamaBridge"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"has-storage-data","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_1\""}}],"actions":[{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"PlaygamaBridge.StorageData(\"key_1\")"}}]},{"eventType":"block","conditions":[{"id":"has-storage-data","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_2\""}}],"actions":[{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"PlaygamaBridge.StorageData(\"key_2\")"}}]}]}]}
```

</details>

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

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

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FjgsLvJOji6Ip3LtTOpnA%2FScreenshot%202024-10-17%20at%206.26.50%E2%80%AFPM.png?alt=media&#x26;token=2f2e3af0-e3fc-4c48-8746-5e3a29ff4e33" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-clicked","objectClass":"Button"}],"actions":[{"id":"append-storage-data-set-request","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_1\"","value":"42"}},{"id":"append-storage-data-set-request","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_2\"","value":"\"test\""}},{"id":"send-storage-data-set-request","objectClass":"PlaygamaBridge","parameters":{"storage-type":"default"}}]},{"eventType":"block","conditions":[{"id":"on-storage-data-set-request-completed","objectClass":"PlaygamaBridge"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"is-last-action-completed-successfully","objectClass":"PlaygamaBridge"}],"actions":[{"type":"comment","text":"success"}]}]}]}
```

</details>

#### Delete Data

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

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FXWiUJ0QJuq1P7sKKnEhB%2FScreenshot%202024-10-17%20at%206.28.04%E2%80%AFPM.png?alt=media&#x26;token=f04f8c92-f306-4681-8a1a-895659ae6045" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-clicked","objectClass":"Button"}],"actions":[{"id":"append-storage-data-delete-request","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_1\""}},{"id":"append-storage-data-delete-request","objectClass":"PlaygamaBridge","parameters":{"key":"\"key_2\""}},{"id":"send-storage-data-delete-request","objectClass":"PlaygamaBridge","parameters":{"storage-type":"default"}}]},{"eventType":"block","conditions":[{"id":"on-storage-data-delete-request-completed","objectClass":"PlaygamaBridge"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"is-last-action-completed-successfully","objectClass":"PlaygamaBridge"}],"actions":[{"type":"comment","text":"success"}]}]}]}
```

</details>


---

# 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/construct-3/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.
