question

digitalmkt avatar image
digitalmkt asked

Passing Parameters to CloudScript and if statement not working

Hi, I'm giving VC to a player based on vars like Catalogversion and itemId after another partner player consumes an item. This is the script that triggers the cloud server function and pass the args and is working fine.

private void ConsumeSuccess(ConsumeItemResult result)

    {
        //iteminstanceid = result.ItemInstanceId;

        Debug.Log("Starting Funcion on Server");

        string clientid = PlayerPrefs.GetString("clientid");

        string itemidmerchant = PlayerPrefs.GetString("itemid");

        string catalogversionmerchant = PlayerPrefs.GetString("catalogversion");

        Debug.Log("Rewarding VC to: " + clientid + ". The item: " + itemidmerchant + ". From catalog: " + catalogversionmerchant);



        PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()

        {

            FunctionName = "SendVcToplayer",

            GeneratePlayStreamEvent = true,

            FunctionParameter = new { Clientidtrader = clientid, Itemidtrader = itemidmerchant, Catalogversion = catalogversionmerchant },



        }, cloudResult =>

        {

            Debug.Log("Server script working fine");



        }, cloudError =>

        {

            Debug.Log("Something went wrong with the server side");



        });



    }

This is the debug log from Xcode. I can see that all params are ok:

"Rewarding VC to: BA9*********84B6. The item: win200free. From catalog: Torrons"

This is the CloudScript that triggers the VC to be sent to the player.

  handlers.SendVcToplayer = function (args, context){
  
      var clientidtrader = args.Clientidtrader;
      var itemidtrader = args.Itemidtrader;
      var catalogversion = args.Catalogversion;
      
      if (args.Catalogversion == "Torrons" && args.Itemidtrader == "web200free") {
      
      server.AddUserVirtualCurrency ({
          Amount: "200",
          PlayFabId: clientidtrader,
          VirtualCurrency: "IB"
          });
          
            return {messageValue: "200IB Granted to Client"};      
      }
      
            server.AddUserVirtualCurrency ({
          Amount: "50",
          PlayFabId: clientidtrader,
          VirtualCurrency: "IB"
          });
      
     return{messageValue: "This is not rewardable"};
  }

The problem is that the "if" statement doesn't understand what is the catalog version and itemid so the Cloudscrip isn't giving the "200" VC to the player, only the "50" (that is given to every player that consumes an item, as a reward.

I also tried using the var:

if (catalogversion == "Torrons" && itemidtrader == "web200free") 

and doesn't work as well.

What I'm doing wrong here? is it java coding related in the CloudScript?

Thank you.

CloudScript
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

According to your client code, the “Itemidtrader” field that you pass in the CloudScript args has the value “win200free”. But the "if" statement is “if (args.Catalogversion == "Torrons" && args.Itemidtrader == "web200free")”. “win200free” does not match with “web200free”. It’s the possible reason that causes the “if” statement’s condition is false.

1 comment
10 |1200

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

digitalmkt avatar image digitalmkt commented ·

You're right. I changed the itemID but the name in the statement still the older.

0 Likes 0 ·

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.