Skip to content

Built-in data


Store data in key-value pairs, built-in object of phaser.

  • Author: Richard Davey



Set value

  • Set value, value);
    or[key] = value;
    • key : Key string.
  • Increase number value. If the key doesn't already exist in the Data Manager then it is increased from 0., data);
    or[key] += value;
    • data : The value to increase.
  • Toggle boolean value. If the key doesn't already exist in the Data Manager then it is toggled from false.;
    or[key] = ![key];

Set values;    // data: {key:value, ...}

Merge values;  // data: {key:value, ...}, false);  // won't overwrite existed keys


Fires setdata event when a value is first set.'setdata', function(parent, key, value){ /* ... */ });

Fires changedata, and changedata- + key events when a value is set that already exists.'changedata', function(parent, key, value, previousValue){ /* ... */ });'changedata-' + key, function(parent, value, previousValue){ /* ... */ });


Get value

var value =;
var value =[key];

Get values

var values =; // values: [value, value, ...], keys: [key, key, ...]

Get all values

var allValues =;  // return a copy of data


Using string.match() to pick matched keys.

var result =;


Remove key;

Remove keys;  // keys: [key, key, ...]

Pop key

var value =;

Get and remove that key.

Delet all keys

Delete all data in this Data Manager and unfreeze it.;


Fires removedata event when a key is removed.'removedata', function(parent, key, value){ /* ... */ });


var isFrozen =; = true;

No changes can be written to it.

Has key

var hasKey =;

For each key, key, value){
    /* ... */
}, scope);

Count of data

var cnt =;


Reset status and clear all keys.