Skip to content

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.

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:

CrazySDK.Data.SetInt("gold", 100);

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. The downside is the data loss that will affect all your players if you don't integrate any migration mechanism from the old data. For example, if you know all the keys stored in PlayerPrefs, you can copy them into the Data module at the game start, and remove them from PlayerPrefs. This should be done only once for each user when the game starts.