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 /
  • General Discussion /
This question was redirected from ExecuteCloudScript Errors - 'ExecuteCloudScriptResult' does not contain a definition
avatar image
Question by agniesportsyt · Nov 19, 2020 at 04:45 PM · CloudScriptFriendsShared Group Data

How to access the variables in the cloud script ?

Now from the above mentioned cloud script, how can I access the variables - keystring, datapayload or messageGroupId in my Unity's C# Script when I call the ExecuteCloudScript. I am confused about the Json concepts and I don't know anything about Java. So please help me to get through this problem. Thank you in advance.

playfab-advanced-cloud-script-22-638.jpg (41.2 kB)
Comment
agniesportsyt

People who like this

1 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 Junjin Chen · Nov 20, 2020 at 07:06 AM

The variables of your Unity Script can be passed to CloudScript through FunctionParameter in Unity, for example:

private static void StartCloudHelloWorld(){  PlayFabClientAPI.ExecuteCloudScript(new
ExecuteCloudScriptRequest()  {  FunctionName =
"helloWorld", // Arbitrary function name (must exist in your uploaded
cloud.js file)  FunctionParameter
= new { name = "YOUR NAME" }, // The parameter provided to your
function 
GeneratePlayStreamEvent = true, // Optional - Shows this event in PlayStream  }, OnCloudHelloWorld, OnErrorShared);}

Then, in CloudScript, you could use the args to access the variables, for example:

handlers.helloWorld = function (args) {
// ALWAYS validate args parameter passed in from clients (Better than we do here)
var message = "Hello " + args.name + "!"; // Utilize the name parameter sent from client
log.info(message);
return { messageValue: message };
}

Please refer to: Writing custom CloudScript

If you have any further questions, please feel free to ask.

Comment
agniesportsyt

People who like this

1 Show 3 · 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 agniesportsyt · Nov 20, 2020 at 01:55 PM 1
Share

Yeah I tried, but I am getting this error : 'ExecuteCloudScriptResult' does not contain a definition for 'message' and no accessible extension method 'message' accepting a first argument of type 'ExecuteCloudScriptResult' could be found (are you missing a using directive or an assembly reference?)

avatar image Junjin Chen agniesportsyt · Nov 23, 2020 at 05:55 AM 0
Share

In Unity, the ‘ExecuteCloudScriptResult’ does not contain message property. Please refer to ExecuteCloudScriptResult or the SDK document to check its structure. To get the function result, you could use ‘result.FunctionResult’ in the successful callback, which is an object. There are plenty ways to parse the object in C# and get its property, an example would be:

  void
OnSuccess(PlayFab.ClientModels.ExecuteCloudScriptResult result)
{
Debug.Log(JsonUtility.FromJson<Hello>(result.FunctionResult.ToString()).messageValue);
}

Where the Hello Class is defined as:

public class Hello
{
public string messageValue;
}
avatar image agniesportsyt · Nov 21, 2020 at 11:59 AM 0
Share

Please I want the answer. I am getting this type of errors for the rest of the variables too

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

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    Related Questions

    SharedGroupData Notification on Desktop 1 Answer

    Can We call Cloud Scripts in Unity - void Update() for receiving a friend request ? 2 Answers

    How to access the variables of cloud scripts in Unity's C# script ? 0 Answers

    ExecuteCloudScript Errors - 'ExecuteCloudScriptResult' does not contain a definition 0 Answers

    Cloud Script Return Value Problem - Null Reference Error 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