dot big bang

Developer API
Menu
All
  • Public
  • Public/Protected
  • All

To use the code examples on this page make sure you have followed the steps on Custom Player Template to get the dbb_player_state script on to your Player.

The systems in Doodle Safari all handle saving data for you, but if you would like to save data with your own scripts you can use the methods below:

// Get the entire key/value state object
this.game.sendEventToTag(“player_state”, "getState", null, (state: any) => {
    // Work with the state here.
});

// Or without a callback
this.game.sendEventToTag(“player_state”, "getState", this.entity);

onGetState(state: any) {
     // Work with the state here.
}

// Get the value of a key
this.game.sendEventToTag(“player_state”, "getValue", null, “mySaveId”, (value: any) => {
    // Work with the value here. value will be undefined if it doesn’t exist!
});

// Or without a callback
this.game.sendEventToTag(“player_state”, "getValue", this.entity, “mySaveId”);

onGetValue(key: string, value: any) {
    // Work with the value here. value will be undefined if it doesn’t exist!
}

// Set the value of a key
this.game.sendEventToTag(“player_state”, "setValue", “mySaveId”, value);

// Increment the numeric value of a key
this.game.sendEventToTag(“player_state”, "incrementValue", “mySaveId”, amount);

// Reset a key
this.game.sendEventToTag(“player_state”, "reset", “mySaveId”);

// Reset the entire state
this.game.sendEventToTag(“player_state”, "reset");

You can also listen for save data changes by adding the player_state_listener tag to your Entity and adding the following methods to your script:

// Called when player state loads. This may never get called in your script depending on the order things are executed in so don’t rely on it
onPlayerStateLoaded(state: any) {}

// Called any time a key is changed
onPlayerStateChanged(key: string, oldValue: any, newValue: any) {}

// Called on each successful save
onPlayerStateSaveSuccess(state: any) {}

// Called on a failed save
onPlayerStateSaveFailed(state: any) {}