question

ryan-2 avatar image
ryan-2 asked

How do I compare title data key/value with client call in cloud script?

I'm using Unity and here's what I'm trying to figure out.

I set custom build version under Title Data. I'm calling Cloud Script function from client side to take in custom build version # (right after it is built in Unity and set in Unity), compare it with build version in Title Data inside Cloud Script, and then return the value.

How do I access key/value pair of Title Data in Cloud Script?

CloudScriptTitle Data
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.

ryan-2 avatar image ryan-2 commented ·

Grrr don't know how to revise the question. It'd be great if code example was provided. Thanks in advance!

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

You can call server.GetTitleData in Cloud Script to access key/value pairs of Title Data. Let’s suppose you saved the build version data in the Title Data, the key is called “BuildVersion” and the value stores the version number. Here is the code example:

handlers.compareBuildVersion = function (args, context){


    //retrieve the version number from title data
    var buildVersion = server.GetTitleData({Keys : ["BuildVersion"]})["Data"]["BuildVersion"]; 
    
    //compare buildVersion with client build version
    
    
}
6 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.

ryan-2 avatar image ryan-2 commented ·

Thanks! Though what does ["Data"] do? Also is there more detailed documentation/guide on how to use CloudScript then Official ExecuteCloudScript Documentation? Having hard time trying to figure out how some of the functions work - such as log.info/debug/error, what does messageValue/inputValue do, when would I actually need to pass for context, etc.

0 Likes 0 ·
ryan-2 avatar image ryan-2 ryan-2 commented ·

In addition, I'm setting title version to following:

handlers.checkVersion = function (args1, args2, context) {
    var oldQABuildVersion = Number(args1.oldTestBuildVersion);

var testVersion = server.GetTitleData({Keys : ["OldTestBuildVersion"]})["Data"]["OldTestBuildVersion"];
    
    testVersion["OldTestBuildVersion"] = oldQABuildVersion;

return { testVersion };
}

but when I refresh Title Data page, versions are not updated. Does it take some time to do this or am I doing something wrong? In Unity I'm getting proper response with increased version number.

0 Likes 0 ·
ryan-2 avatar image ryan-2 ryan-2 commented ·

uh solved myself. Also is Postman the only way to learn more about Playfab? tutorial page doesn't really match up with current Postman...

0 Likes 0 ·
Show more comments
Citrus Yan avatar image Citrus Yan ryan-2 commented ·

The object returned by server.GetTitleData({Keys:["BuildVersion"]}) is in the following format:

"Data": {
 "BuildVersion": "1.20191120"
 }

In order to access the value, you need to do ["Data"] first.

This doc talks about Cloud Script in a more detailed way: CloudScript Tutorials

0 Likes 0 ·
brandon@uprootstudios.com avatar image
brandon@uprootstudios.com answered

One of the ways we do it is by de-serializing the returned JSON object

foreach (var titleData in result.Data) {
    if (titleData.Key.Equals("ServerRegions")) {
	var serverRegions = (JsonObject)PlayFabSimpleJson.DeserializeObject(
	    titleData.Value
	);
	var regionArray = (JsonObject)serverRegions["Regions"];
	foreach (var region in regionArray) {
	    serverRegionList.Add(region.Value.ToString());
	}
    }
}
10 |1200

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

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.