Sign In Register

How can we help you today?

Start a new topic

How do I copy a player?

I'm creating a functionality to copy a given player to a separated database, where devs could afterwards, copy that player into their player so they could easily get into a certain "stage", or "game state", to help debug, find problems.

I tried to do something like this:
 
var db = Spark.getGameDataService();
var entry = db.createItem("snapshots", snapshotId);

var copyPlayer = Spark.loadPlayer(_playerId);

//also tried without JSON.stringify
entry.setData(JSON.stringify(copyPlayer));

var status = entry.persistor().persist().error();

 

 It doesn't work because the Player data doesn't have a toString nor a toJson function implemented. Also didn't find a way to query in the system database.


Any way to accomplish this without having to read all achievements, all leaderboards scores, all etc?


The data in snapshots will be used later on to replace or create a player.


Thanks in advance!

 

1 Comment

I don't use the new Game Data Service but if the system for player data is still the same, I believe that Spark.loadPlayer is a special class which hides mongoDB queries and it doesn't actually contains data.

We tried to do something similar but unfortunately all the functionality are not available within cloud code or the REST API to perform such a task.

Login to post a comment