question

tarekonatsheh avatar image
tarekonatsheh asked

Adding and reading data from/to Entity Objects using Cloud Script

Hi Guys,

I am trying to save/read/delete data into Objects when certain event happen by running a function in Cloud Script, but was not successful.

There is a sample function called "makeEntityAPICall" but when I run it I get the following error:

{
    "FunctionResult": null,
    "Logs": [],
    "ExecutionTimeSeconds": 0.0006393,
    "MemoryConsumedBytes": 27832,
    "APIRequestsIssued": 0,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "JavascriptException",
        "Message": "JavascriptException",
        "StackTrace": "TypeError: Cannot read property 'Entity' of undefined\n    at handlers.makeEntityAPICall (4B66E-main.js:107:31)"
    }
}

Please forgive my ignorance since I am new to this.

Thanks

CloudScriptentitiesdata
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image Seth Du ♦ commented ·

May I ask what's your title ID and Cloud Script version so that we can look into it.

0 Likes 0 ·
tarekonatsheh avatar image tarekonatsheh Seth Du ♦ commented ·

My title ID is 4B66E

Regarding Cloud Script version, I think that there is no versioning in Cloud Script anymore.

But there are revisions, and mine is Revision 16.

0 Likes 0 ·

1 Answer

·
Seth Du avatar image
Seth Du answered

The reason why you get this error is you are using the wrong API. For entity related Cloud Script function, the correct API is Execute Entity Cloud Script, as you can see context.currentEntity is used, instead of currentPlayerId in the function.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tarekonatsheh avatar image tarekonatsheh commented ·

Thanks SethDu for your replay, but I think I was not clear in my question.

What do I need is actually to use functionalities such as "SetObject" and "GetObject" like in the following:

https://api.playfab.com/docs/tutorials/entities/getting-started-entities

But with a Cloud Script code rather than a Unity C# code.

The reason is the huge amount of player data I want to save, and it is more convenient to have them in the (Entity Objects) rather than (Player Data).

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ tarekonatsheh commented ·

Yes, the thing is when you try to call the Cloud Script functions that are related to entity, you should call ExecuteEntityCloudScript rather than ExecuteCloudScript.

for example, the cloud script function:

handlers.setobjecttest = function (args, context) {
    var entityProfile = context.currentEntity;
    var apirequest = {
        Objects: [
            {
                "ObjectName": "SaveSate",
                "DataObject": {
                    "PlayerDetails": {
                        "MapPosition": [
                            22,
                            37.78
                        ],
                        "IsPaidUpgrade": true
                    }
                }
            },
            {
                "SimpleStatements": {
                    "Read": [
                        {
                            "Friend": true
                        }
                    ]
                }
            }
        ],
        Entity: entityProfile.Entity
    }
    var apiresult = entity.SetObjects(apirequest);
}

the ExecuteEntityCloudScript API call request

{
  "FunctionName": "setobjecttest",
  "RevisionSelection": "Live",
  "GeneratePlayStreamEvent": true
}
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ tarekonatsheh commented ·

>>""TypeError: Cannot read property 'Entity' of undefined\n at handlers.makeEntityAPICall (4B66E-main.js:107:31)""

In terms of this error, try to replace "Entity" with "entity"

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.