-
Notifications
You must be signed in to change notification settings - Fork 9
Data Persistence
Mat Hopwood edited this page Jun 13, 2019
·
4 revisions
IGX supports saving user game data sever side via the StorageService allowing the user to play a game from any device and continue play from where they left off. User data is also stored to the browser local storage as a back-up just in case.
The storage service is created in the same way as other services, e.g:
new StorageService("xtralife");
Note that if you called FBInstant.createDefaultServices() to create the default services then you should not recreate the storage service module.
var data = {
best_scores: [100, 200],
name: "Mat",
};
FBInstant.player.setDataAsync(data)
.then(function() {
});
Note that saving uses add and replace. If a property already exists then it will be replaced, if a property does not exist then it will be added. This enables small amounts of data to be saved as and when required, rather than having to save the entire state very time.
FBInstant.player.getDataAsync(["best_scores", "name"])
.then(function(data) {
// Data loaded {best_scores, name}
}).catch(function(error) {
// Error loading data
});
