question

Oleksii avatar image
Oleksii asked

How to get Player Data (Title) via CloudScript

Hello Everyone,

I'm newbie in CloudScripting and i'm trying to figure it out how to get Player Data(Title) via CloudScript, so I have such kind of data in Player Data(Title) like you can see on image

my function to get this data looks like this:

handlers.titledataTest = function (context) {




    var getPlayerInfo = server.getTitleDataRequest(
        {
            PlayFabId: currentPlayerId,
            Keys: ["Info"],
        })
    
    
    // get the key
    var getTitleDataResponse = server.GetTitleData(getPlayerInfo);
    var playerTitleData = JSON.parse(getTitleDataResponse.Data.Info.Value);
    return playerTitleData;
}

I try to run this function via Payers CloudScript, but i've got an error:

{
    "FunctionResult": null,
    "Logs": [],
    "ExecutionTimeSeconds": 0.0005833,
    "MemoryConsumedBytes": 5376,
    "APIRequestsIssued": 0,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "JavascriptException",
        "Message": "JavascriptException",
        "StackTrace": "TypeError: server.getTitleDataRequest is not a function\n    at handlers.titledataTest (9C085-main.js:35:32)\n    at Object.invokeFunction (Script:116:33)"
    }
}

What i'm doing wrong? Thank you!

CloudScript
screenshot-2.png (11.0 KiB)
10 |1200

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

1 Answer

·
Seth Du avatar image
Seth Du answered

getTitleDataRequest is a class defined only in some strong typing language SDK. Since Javascript is weak typing:

var getPlayerInfo ={
	PlayFabId: currentPlayerId,
	Keys: ["Info"]    
};
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.

Oleksii avatar image Oleksii commented ·

Thank You for response now my code looks loke this:

handlers.titledataTest = function (context) {


    var getPlayerInfo = {
	    PlayFabId: currentPlayerId,
	    Keys: ["Info"],        
    };
    
    // get the key
    var getTitleDataResponse = server.GetTitleData(getPlayerInfo);
    var playerTitleData = JSON.parse(getTitleDataResponse.Data.Info.Value);
    return playerTitleData;
}

but i've got another error:

{
    "FunctionResult": null,
    "Logs": [],
    "ExecutionTimeSeconds": 0.0196493,
    "MemoryConsumedBytes": 7464,
    "APIRequestsIssued": 1,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "JavascriptException",
        "Message": "JavascriptException",
        "StackTrace": "TypeError: Cannot read property 'Value' of undefined\n    at handlers.titledataTest (9C085-main.js:41:69)\n    at Object.invokeFunction (Script:116:33)"
    }
}
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Oleksii commented ·

As the error indicates, there is no keyword named "Value" in Cloud Script. You may parse "getTitleDataResponse.Data.Info"

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

The question is mostly about JavaScript Syntax, as Cloud Script is based on Google V8 Engine with native JavaScript language. I suggest finding more reference from JavaScript | MDN (mozilla.org)

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.