I'm trying to implement something very similar to the documentation in Managing Data Persistence - Custom Data. However I'm getting this error cannot call "getData" of null. My cloud code:
var clientTimeKey = Spark.getData().TimeKey;
var API = Spark.getGameDataService();
var entryObject = API.getItem("timeKey", clientTimeKey); // ("dataTypeName", "entryID")
//If error attempting to retrieve entry
// need to add a new item
entryObject = API.createItem("timeKey", clientTimeKey);
var data = entryObject.getData();
data.groupID = 1;
data.count = 0;
var entry = entryObject.document();
var data = entry.getData(); // cannot call "getData" of null;
If I can't retrieve the item then I attempt to create a new item - maybe this is my problem? I'm don't have much experience with js. Any help would be appreciated.
I did figure this out eventually. Reading the documentation I assumed I would get an error if the item was null, but that's not the case. I'm actually not sure what cases the error does catch.