question

monti avatar image
monti asked

Cannot read property 'Entity' of undefined

hi, i'm trying to create a group on playfab by calling a function from construct 3, via the cloudscript addon,

//this is the code on revision

handlers.createGroup = function (args, context) {

var entityProfile = context.currentEntity;

var apiResult = entity.CreateGroup({

Entity: entityProfile.Entity,

GroupName: "Example Group01"

});

return {

apiResult

};

}


But this code comes out in the playstream: "Cannot read property 'Entity' of undefined"

what i need to change in my code? How do i get the entity to read?

I am waiting for an answer to be able to proceed with my app, thanks for your attention.

10 |1200

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

JayZuo avatar image
JayZuo answered

According to your error, the problem here might be the missing of "context.currentEntity".

"context.currentEntity" is specified in the 'ExecuteEntityCloudScript' request. Defaults to the authenticated entity in the X-EntityToken header. So, please make sure your function is called using the ExecuteEntityCloudScript API correctly.

10 |1200

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

monti avatar image
monti answered
{
    "EventName": "player_executed_cloudscript",
    "Source": "CloudScript",
    "FunctionName": "createGroup",
    "CloudScriptExecutionResult": {
        "FunctionName": "createGroup",
        "Revision": 137,
        "FunctionResult": null,
        "FunctionResultTooLarge": null,
        "Logs": [],
        "LogsTooLarge": null,
        "ExecutionTimeSeconds": 0.0004648,
        "ProcessorTimeSeconds": 0,
        "MemoryConsumedBytes": 262968,
        "APIRequestsIssued": 0,
        "HttpRequestsIssued": 0,
        "Error": {
            "Error": "JavascriptException",
            "Message": "JavascriptException",
            "StackTrace": "TypeError: Cannot read property 'Entity' of undefined\n    at handlers.createGroup (D1D36-main.js:7:23)\n    at Object.invokeFunction (Script:117:33)"
        }
    },
    "EventNamespace": "com.playfab",
    "EntityType": "player",
    "TitleId": "D1D36",
    "EntityId": "9DE53A278E3C8BBA",
    "EventId": "22b7ff01a83349208dfb3a3bfb3ed0c4",
    "SourceType": "BackEnd",
    "Timestamp": "2021-10-07T10:05:13.8283062Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null,
    "PlayFabEnvironment": {
        "Vertical": "master",
        "Cloud": "main",
        "Application": "logicserver",
        "Commit": "25e41b6"
    } 

@Jay Zuo

1 comment
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 ·

If you call client API ExecuteCloudScript, you won't get entity data in context. If it is the case, you may replace this API with ExecuteEntityCloudScript

0 Likes 0 ·
monti avatar image
monti answered

Got it, but I can't seem to understand the reason why if I use this code, the feedback is a success, but the group doesn't exist at all!

handlers.checkContext = function(args, context){
    var url = "https://D1D36.playfabapi.com/CloudScript/ExecuteEntityCloudScript";
    var responseString =  http.request(url,method,contentBody,contentType,headers);
    var method = "post";
    var contentBody = "";
    var contentType = String;
    var headers = {};
    var EntityChain = {};
    var EntityId = {};
}

Y'all can find the response right there:

    "EventName": "player_executed_cloudscript",
    "Source": "CloudScript",
    "FunctionName": "CreateGroup",
    "CloudScriptExecutionResult": {
        "FunctionName": "CreateGroup",
        "Revision": 205,
        "FunctionResult": null,
        "FunctionResultTooLarge": null,
        "Logs": [],
        "LogsTooLarge": null,
        "ExecutionTimeSeconds": 0.0002365,
        "ProcessorTimeSeconds": 0,
        "MemoryConsumedBytes": 1312,
        "APIRequestsIssued": 0,
        "HttpRequestsIssued": 0,
        "Error": null
    },
    "EventNamespace": "com.playfab",
    "EntityType": "player",
    "TitleId": "D1D36",
    "EntityId": "9DE53A278E3C8BBA",
    "EventId": "adf4ff43ea754bf28b1c3ef8132483ef",
    "SourceType": "BackEnd",
    "Timestamp": "2021-10-11T09:35:28.8077074Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null,
    "PlayFabEnvironment": {
        "Vertical": "master",
        "Cloud": "main",
        "Application": "logicserver",
        "Commit": "25e41b6"
    } 
1 comment
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 ·

Shared Group and Entity Group is different and so are the purposes. Please refer to Using Shared Group Data - PlayFab | Microsoft Docs to know the usage.

Entity Group is the "Group" tab you can see in the Game Manager, and it is more like Clans or Parties. Please check Entity Groups - PlayFab | Microsoft Docs

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.