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 oskar · Nov 08, 2019 at 01:39 PM · CloudScriptunity3d

FunctionResult missing from ExecuteCloudScriptResult

I'm pulling my hair over this issue. I'm trying out Unity with PlayFab for the first time and can't even get the simplest "hello world" type cloud script call to work. Whatever I do the response comes back without FunctionResult in it. I do however get all the other data like ExecutionTimeSeconds, Revision and whatnot.

Calling the cloudscript handler/function from game manager works. Then FunctionResult is included in the response but from within Unity it isn't. I've also tried both returning a naked string as well as wrap it in a json. Same outcome.

I can see here in the forums that people have had similar issues in the past but that was ages ago and I've also made sure I'm not making any of the mistakes pointed out in those old threads.

Can you please advise? My title id is 1D80.

Thanks

Comment

People who like this

0 Show 2
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
avatar image oskar · Nov 08, 2019 at 01:40 PM 0
Share
PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new ExecuteEntityCloudScriptRequest()
            {
                Entity = new PlayFab.CloudScriptModels.EntityKey { Id = entityId, Type = entityType },
                FunctionName = "Hello",
                RevisionSelection = CloudScriptRevisionOption.Latest


            }, OnPlayFabEntityCloudScriptExecuted, OnPlayFabError/*, customData, extraHeaders*/);

avatar image oskar · Nov 08, 2019 at 01:41 PM 0
Share
handlers.Hello = function(args, context) {
    log.debug("Hello called!");
    var response = {"msg": "OH CMON!"};
    return response;
}

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by oskar · Nov 11, 2019 at 09:53 AM

There is this caveat that if using the standard C# JsonUtility the FunctionResult won't be recognized. You have to use PlayFabs PlayFabSimpleJson to be able to log the result.

Debug.Log(JsonUtility.ToJson(result.FunctionResult)); // =>> {}
Debug.Log(PlayFabSimpleJson.SerializeObject(result.FunctionResult)); // =>> prints the response object properly 
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
avatar image

Answer by Sarah Zhang · Nov 11, 2019 at 07:03 AM

Your CloudScript function has run successfully, and you have got the function result. You can navigate to [GameManager]->[Data]->[Event History], use the [Show JSON] button (arrow icon on the item’s left) to expand the details of items [player_executed_cloudscript SUCCESS: Hello() (revision xx)], you will find the function result in their JSON. So, API and your process work fine. It looks like the problem is in the Unity’s client code, you can try to refer to the doc Writing custom CloudScript to modify it.

In addition, you can use ExecuteCloudScript instead of ExecuteEntityCloudScript in your code. ExecuteEntityCloudScript should be used when you want to execute Entity API on Cloud Script. Executing “Hello” function doesn’t need to use it.

Comment
oskar

People who like this

1 Show 1 · 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
avatar image oskar · Nov 11, 2019 at 09:45 AM 0
Share

I realize I wouldn't need to use ExecuteEntityCloudScript for this simple cloudscript function but my aim is to eventually make use of Entity Api so this was just a first little step where I unfortunately ran into problems right away.

You're right tho that the issue was in my client code. By using the code at the bottom I can get a hold of the returned value. Very frustrating tho that when just logging the full result of the cloudscript function with

Debug.Log(JsonUtility.ToJson(result.FunctionResult)); // =>> {}

the sdk treats it as if the FunctionResult just isn't there. Very un-intuitive.

private static void OnCloudHello(ExecuteCloudScriptResult result)
    { 
        Debug.Log(PlayFabSimpleJson.SerializeObject(result.FunctionResult));
        JsonObject jsonResult = (JsonObject)result.FunctionResult;
        object responseMessage;
        jsonResult.TryGetValue("msg", out responseMessage);
        Debug.Log((string)responseMessage);
    }

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

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Store with random items 1 Answer

    Cloud Script FunctionResult Returns Null 2 Answers

    Server/RedeemMatchmakerTicket working on Unity Editor, not in Android device 1 Answer

    Azure Function failed calling via Rules 2 Answers

    "RaiseEvent() failed. " warning occurred in Unity 1 Answer

    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