Data
The data module allows to save and retrieve user data for logged in CrazyGames users. The data will also be synced on all the devices where the user plays the game.
If the user is not logged in, the data module will store the game data in browser LocalStorage. If the user logs in later, the LocalStorage game data will be synced and backed up on the user's account.
Warning
If you intend to use the data module, don't forget to select the appropriate toggle in the "Does your game save progress?" form when submitting the game. The data module will be disabled otherwise.
Using the data module
The data module has the same API as the PlayerPrefs:
void SetInt(string key, int value);
int GetInt(string key);
int GetInt(string key, int defaultValue);
void SetFloat(string key, float value);
float GetFloat(string key);
float GetFloat(string key, float defaultValue);
void SetString(string key, string value);
string GetString(string key);
string GetString(string key, string defaultValue);
bool HasKey(string key);
void DeleteKey(string key);
void DeleteAll();
You can call methods from the data module like this:
Guest user behaviour
For the guest users, the data module stores the game data in localStorage. When a guest user signs in, you don't need to do anything. Our SDK will automatically load the account game data if there is any, or if this user hasn't played your game before, the SDK will transfer the guest data to the user account.
When the user signs out, the SDK will revert back to using the guest game data.
QA Tool
The data module works in QA Tool, however it doesn't sync the data. This means that regardless of what user you select in the User simulation modal, your game will always have the same data.
Data saving
The SDK debounces data saving with 1 second, meaning that multiple calls to the Set
or Delete
methods will be saved after 1 second. There may be exceptions in various cases, when data saving may be debounced with more time, up to 30 seconds.
There is a 1MB data limit. If you are approaching it, you will see warnings in the browser console. The data won't be backed up anymore if it exceeds 1MB.
Integrating data module into already published games
Since the Data
module offers the same API as PlayerPrefs
, it is quite easy to integrate it into your already published games. To avoid players losing their data, you should copy all the existing PlayerPrefs keys into the Data
module for the players who played your game before.