Skip to content

Commit e366546

Browse files
committed
Persisting extra fields
1 parent cc1c9d7 commit e366546

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Members of `Player`:
201201
* `player.username`
202202
* `player.score`
203203
* `player.hasLeftGame`
204+
* `player.extraFields`: Dictionary of extra fields defined in your database schema. These will be persisted automatically.
204205

205206
Your project must create a `GameDelegate` and pass it into `ostracodMultiplayer.initialize`. `GameDelegate` must have the following members:
206207

gameUtils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ Player.prototype.tick = function() {
6464

6565
Player.prototype.persist = function(done) {
6666
var self = this;
67+
var tempFieldSet = {score: self.score};
68+
var name;
69+
for (name in this.extraFields) {
70+
tempFieldSet[name] = this.extraFields[name];
71+
}
6772
dbUtils.performTransaction(function(callback) {
6873
accountUtils.updateAccount(
6974
self.accountUid,
70-
{score: self.score},
75+
tempFieldSet,
7176
function(error, result) {
7277
if (error) {
7378
console.log(error);

0 commit comments

Comments
 (0)