question

agniesportsyt avatar image
agniesportsyt asked

Cloud Script Return Value Problem - Null Reference Error

//I was trying to make Friend Request method using cloud scripts and SharedGroupData. I provided the all of my code below. Please help me find my mistake.



 public void ReceiveFR()
   {
      FRObject.SetActive(false);
      PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
     {
            FunctionName = "checkFriendRequests",
            FunctionParameter = false,
            GeneratePlayStreamEvent = true
     }, OnReceiveFR =>
     {
          
         JsonObject jsonresult = (JsonObject)OnReceiveFR.FunctionResult;
         object FRsender;
         object message;
         jsonresult.TryGetValue("message", out message);    // This is the 278th line
         
            FRmsg.text = message.ToString();
    

         jsonresult.TryGetValue("FRsender", out FRsender);
         
            rid = FRsender.ToString();
         
         Debug.Log((string)FRsender);
    }, DisplayPlayFabError);
   }

apisCloudScriptShared Group DataFriends
screenshot-6.png (109.0 KiB)
screenshot-7.png (30.9 KiB)
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

·
Sarah Zhang avatar image
Sarah Zhang answered

The problem is from CloudScript function. Please modify the sentence “var message = JSON.parse(messageList.Data[key].Value);” to “var message = messageList.Data[key].Value;”. JSON.parse(text) method requires the incoming parameter is the valid JSON string. “messageList.Data[key].Value” doesn’t meet the requirement, so it would return the SyntaxError. If you want to log the SyntaxError, this sentence “log.info(e.stack);” would work. We suggest you also add the SDK error handling on the client. Please check this document -- SDK error handling best practices for more information.

7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

agniesportsyt avatar image agniesportsyt commented ·

Ok I did as you said, I modified the sentence to var message = messageList.Data[key].Value

But still I am getting the same error. Can you please help me? Please

0 Likes 0 ·
agniesportsyt avatar image agniesportsyt commented ·

I am really sorry to comment again but the solution that you gave didn't has any affect. The error still appears. Please help me.

0 Likes 0 ·
agniesportsyt avatar image agniesportsyt commented ·

I am just reminding you, please answer me. The error hasn't fixed yet. Please reply and help me fix the issue.

0 Likes 0 ·
agniesportsyt avatar image agniesportsyt commented ·

Why PlayFab is not responding to my problem? The solution that you gave didn't solve my problem. Please reply and help me.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang agniesportsyt commented ·

Thanks for the patience. Could you please follow this document -- SDK error handling best practices to handle the error then provide the detailed error messages? The Null Reference exception can't be used to target the specific error.

0 Likes 0 ·
agniesportsyt avatar image agniesportsyt Sarah Zhang commented ·

I tried to generate playstream and this is what I got. The result is always null and I think the root problem is the InvalidSharedGroupId do you have any idea about this?

0 Likes 0 ·
Show more comments

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.