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 Alen Jose · Apr 01, 2020 at 11:30 AM · CloudScriptunity3d

Json related query

Hi,

So I have a cloud script with this function:

handlers.SelectEvent=function SelectEvent(args, context)

{ var message = "2" + currentPlayerId + "!";

log.info(message); var inputValue = null; if (args && args.inputValue) inputValue = args.inputValue;

log.debug("helloWorld:", { input: args.inputValue }); return { messageValue: message };

}

and in Unity C# I have:

public void startCloudScript () { PlayFabClientAPI.ExecuteCloudScript (new PlayFab.ClientModels.ExecuteCloudScriptRequest () { FunctionName = "helloWorld", FunctionParameter = null, GeneratePlayStreamEvent = false }, OncloudEvent, Error) ; }

for starting the function execution and:

void OncloudEvent (PlayFab.ClientModels.ExecuteCloudScriptResult res)

{

Debug.Log (res.FunctionName);

Debug.Log( PlayFab.Json.PlayFabSimpleJson.SerializeObject (res.FunctionResult));

}

for getting the result.

The issue I have is that even though I can get the function name from the first Debug statement in OnCloudEvent(), the second statement always returns null.

I want to be able to see the message that I have sent from the CloudScript.

How would I go about this?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Alen Jose · Apr 07, 2020 at 05:54 AM

i just remove :

log.info(message); var inputValue = null; if (args && args.inputValue) inputValue = args.inputValue;

log.debug("helloWorld:", { input: args.inputValue }); return { messageValue: message };

from the cloudscript and it worked

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 Citrus Yan · Apr 02, 2020 at 06:02 AM

The FunctionName is "helloWorld" in your C# code, however, the one in your CloudScript is "SelectEvent". Generally, you'll get a response similar to the following if you provide the wrong function name which does not exist in CloudScript:

{
    "code": 200,
    "status": "OK",
    "data": {
        "FunctionName": "xxx",
        "Revision": 89,
        "Logs": [],
        "ExecutionTimeSeconds": 0.00017099999999999998,
        "ProcessorTimeSeconds": 0.0,
        "MemoryConsumedBytes": 3304,
        "APIRequestsIssued": 0,
        "HttpRequestsIssued": 0,
        "Error": {
            "Error": "CloudScriptNotFound",
            "Message": "No function named xxx was found to execute",
            "StackTrace": ""
        }
    }
}

Which I think explains why you received null from res.FunctionResult because in this case, that field doesn't exist at all. Would you please check your code again?

Comment

People who like this

0 Show 4 · 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 Alen Jose · Apr 02, 2020 at 06:45 AM 0
Share

Ah, I'm sorry both are actually named SelectEvent. I can get the name of the function in the debug statement but not the result.

avatar image Citrus Yan Alen Jose · Apr 02, 2020 at 07:39 AM 0
Share

Would you please use

Debug.Log(PlayFab.Json.PlayFabSimpleJson.SerializeObject(res));

to inspect the complete result?

avatar image Alen Jose Citrus Yan · Apr 03, 2020 at 05:19 AM 0
Share

This is the error that I get:

{"APIRequestsIssued":0,"Error":{"Error":"JavascriptException","Message":"JavascriptException","StackTrace":"TypeError: Cannot read property 'inputValue' of null\n at handlers.helloWorld (58578-main.js:50:44)\n

Show more comments
avatar image

Answer by Alen Jose · Apr 05, 2020 at 05:53 PM

@Citrus Yan any further advice?

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

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Can a CloudScript call a function on a client? 2 Answers

    Unity: player has not played this title? 1 Answer

    Using Custom Tags with Email verification rule 1 Answer

    Unity PUN2 Room creation error 1 Answer

    Unity ExecuteFunction error: Cannot connect to destination host 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