question

brendan avatar image
brendan asked

Help on cloud server script

inesmoital
started a topic on Mon, 06 April 2015 at 4:04 PM

Hello again,

I'm trying to do some cloud code but I'm getting an error in Unity.

My cloud code looks like this:

function getWeekNumber(d) {
    d = new Date(+d);
    d.setHours(0,0,0);
    d.setDate(d.getDate() + 4 - (d.getDay()||7));
    var yearStart = new Date(d.getFullYear(),0,1);
    var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7)
    return [d.getFullYear(), weekNo];
}

handlers.getWeeklyLeaderboard = function(args){
    var leaderboard_week_number = server.GetTitleData({
        Keys: ["WeeklyHighScoreLeaderboard_ActiveWeek"],
    })[0];

    var this_week_number = getWeekNumber(new Date());

    if(this_week_number > leaderboard_week_number){
        server.SetTitleData({
            Key: "WeeklyHighScoreLeaderboard_ActiveWeek",
            Value: this_week_number
        })
    }
}

And I'm calling it in Unity like this:

RunCloudScriptRequest request = new RunCloudScriptRequest();
request.ActionId = "getWeeklyLeaderboard";

PlayFabClientAPI.RunCloudScript(request, Test, ErrorTest);

And I'm getting an error saying "<url> malformed". Can you help me on finding out what am I doing wrong?

Thanks

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

·
brendan avatar image
brendan answered

Best Answer
Brendan Vanous said on Mon, 06 April 2015 at 7:34 PM

Please make sure that GetCloudScriptUrl is called once, after startup of your title, to make certain that the URL is properly configured for your title. If that's already been done, could you send us a repro showing this behavior, so that we can investigate?

Brendan


10 Comments
Brendan Vanous said on Mon, 06 April 2015 at 7:34 PM

Please make sure that GetCloudScriptUrl is called once, after startup of your title, to make certain that the URL is properly configured for your title. If that's already been done, could you send us a repro showing this behavior, so that we can investigate?

Brendan


inesmoital said on Tue, 07 April 2015 at 11:19 AM

Hi Brendan,

Thanks that was the problem, I wasn't calling GetCloudScriptUrl. But now I'm getting another error: CloudScriptNotFound. Any idea on what might be the problem?


Brendan Vanous said on Tue, 07 April 2015 at 2:54 PM

A few questions:

What's the Title ID you're testing?

For that title, what Version are you passing in for GetCloudScriptUrl, and is Testing set to true or false?

In the Version, what Revision has been pushed live?

What's the handler you're calling in RunCloudScript?


inesmoital said on Tue, 07 April 2015 at 3:04 PM

Hi Brendan,

  • The TitleID is 8add.

  • I'm not passing any version to GetCloudScriptUrl (as it is optional I assumed that it was getting the latest). I'm not setting anything on the GetCloudScriptRequest I'm letting everything on default.

GetCloudScriptUrlRequest request = new GetCloudScriptUrlRequest();
PlayFabClientAPI.GetCloudScriptUrl(request, OnGetCloudScript, OnPlayfabError);

  • If I understood how the handlers can be called and work, I'm setting:

RunCloudScriptRequest request = new RunCloudScriptRequest();
request.ActionId = "getWeeklyLeaderboard";

So I'm assuming it is calling "getWeeklyLeaderboard" handler on the server.


Brendan Vanous said on Tue, 07 April 2015 at 3:20 PM

Ah, then that would be the issue. RunCloudScript executes the latest live revision, if you don't set the Testing bool to true. Your revision with the getWeeklyLeaderboard handler is Revision 2, which is not live. If you push that revision live, your current code will be hitting the correct revision. Otherwise, you could set Testing to true in the RunCloudScript call, in which case the most recent revision will be the one used.

Brendan


inesmoital said on Thu, 09 April 2015 at 2:06 PM

Hi Brendan,

Ok looks like it's running now but the following code didn't change the title data. Do you know why?

function getWeekNumber(d) {
    d = new Date(+d);
    d.setHours(0,0,0);
    d.setDate(d.getDate() + 4 - (d.getDay()||7));
    var yearStart = new Date(d.getFullYear(),0,1);
    var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7)
    return [d.getFullYear(), weekNo];
}

handlers.getWeeklyLeaderboard = function(args){
    var leaderboard_week_number = server.GetTitleData({
        Keys: ["WeeklyHighScoreLeaderboard_ActiveWeek"],
    })[0];

    var this_week_number = getWeekNumber(new Date());

    if(this_week_number > leaderboard_week_number){
        server.SetTitleData({
            Key: "WeeklyHighScoreLeaderboard_ActiveWeek",
            Value: this_week_number
        })
    }
}

inesmoital said on Thu, 09 April 2015 at 2:07 PM

By the way leaderboard_week_number should be 0. Is there a way to debug the server side?


Brendan Vanous said on Thu, 09 April 2015 at 5:58 PM

Hi Ines,

On the Set call, bear in mind that both the key and value must be strings. Right now, your this_week_number is a numeric value, which won't work.

I would also recommend having a look at the base sample Cloud Script in our GitHub (it's also being set up automatically as the first revision for all new titles). It has a lot of good examples of making calls from Cloud Script.

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.