Sign In Register

How can we help you today?

Start a new topic

GameDataService: cannot call "getData" of null

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

    if (entryObject.error())

    {

        // need to add a new item

        entryObject = API.createItem("timeKey", clientTimeKey);

        var data = entryObject.getData();

        

        data.groupID = 1;

        data.count = 0;

        

        // entryObject.persistor().persist();

    } 

    

    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.


Josh




1 person has this question

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.

I suggest you to read carefully this:
https://docs.gamesparks.com/getting-started/using-cloud-code/unity-cloud-code.html
I had the same difficulty learning how the cloud code works and this helped me.

 

Login to post a comment