Thanks Steve, Can i create a list with player data, i mean using insert new field, or removing a specific field, or i have to send the whole data as a string and convert it to array via code??
Hi Ahmed,
That should be perfectly possible. One way you might go
about it is like so below. This would be similar for arrays as well,
where you could use push to add to an array or slice to make a new array
minus the data you wish to remove. Does this make sense? I hope this
helps.
Kind regards,
- Steve
// Add to a document
var player = Spark.getPlayer();
var playerData = player.getPrivateData("dataKey");
playerData.newKey = "myNewListData";
player.setPrivateData("dataKey", playerData);
// Remove from a document
var player = Spark.getPlayer();
var playerData = player.getPrivateData("dataKey");
delete playerData.keyToRemove;
player.setPrivateData("dataKey", playerData);
Hello Kevin,
I tried your script but it returns error in the test harness because player data is null, even if i set player data it still return only on field, also i read that privatedata are not suppose to be send to the device, and i need to send the whole inventory to the player when he start the game.
Thanks,
Can you explain me more how to set the playerID as a key to an object array in the runtime Collections. i tried Spark.runtimeCollection("playerInventory/" + playerID) Didn't work it create a new Collection every time, and this is not what i intended, i wanted to create a hierarchy as Collection/playerID/ fields of user data.
Ahmed Tayseer
I was working on creating a list of items that was bought inside the game, and i followed this tutorial, am not convinced this is the best way to do what i want because i have to go through all fields in the runtime collection and pick the ones only related to the player, is there a way to organize the data in a way so that i can add list under each user ID, in general is this the best way to store a list relative only to the player, Thanks