Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Brendan · Oct 05, 2015 at 12:43 AM ·

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

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Oct 05, 2015 at 12:43 AM

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.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    No one has followed this question yet.

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges