question

Nykos avatar image
Nykos asked

Unity OpenTrade

Hi, my name is Nicolas, and i am new to playfab, actualy i am new to pretty much anything server related. I've been using unity for almsot six years and know it very well, having done many games.

Here's the deal: i've been trying to integrate openTrade i my current game, but i must be doing something wrong because nothing works.

Could someone be kind enough to explain me how do i call openTrade in unity?

I have set different items in my catalog, set them as tradable, for example their id is ItemCorn, ItemSugar, etc...

And i'm getting Error Code 1000, Invalid Param

Thanks in advance if someone can help me, i'm realy lost here.

 

Nicolas

10 |1200

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

brendan avatar image
brendan answered

How about we simplify this, so that you can just get a basic version of this going that you can later expand upon? And since the PlayFab ID you were passing in was the one for the local user, we can safely leave that out (in order to make the trade allowable for others). Also, "ItemPotato" had a typo in the code above, so fixing that. You will, however, need to define your callbacks:

  var openRequest = new ClientModels.OpenTradeRequest();
  openRequest.RequestedCatalogItemIds = new string[] { "ItemGrapes", "ItemSugar" };
  openRequest.OfferedInventoryInstanceIds = new string[] { "ItemCorn", "ItemPotato", "ItemOlive" };
  PlayFabClientAPI.OpenTrade(openRequest, OpenTradeCallback, ErrorCallback);

Can you give something like this a try?

10 |1200

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

Nykos avatar image
Nykos answered

Hi, still not working. I tried two versions, the first in qhich i let the params declared in the funciton:

 

public static void OpenTrade(params string[] offeredInventoryInstanceIds)
  {
   var openRequest = new ClientModels.OpenTradeRequest ();
   openRequest.RequestedCatalogItemIds = new List<string>() { "ItemGrapes", "ItemSugar" };
   openRequest.OfferedInventoryInstanceIds = new List<string>() { "ItemCorn", "ItemPotato", "ItemOlive" };
   PlayFabClientAPI.OpenTrade (openRequest, OpenTradeCallback, FailCallback("OpenTrade"));
  }

and a second in which i removed the params:


  public static void OpenTrade2()
  {
   var openRequest = new ClientModels.OpenTradeRequest ();
   openRequest.RequestedCatalogItemIds = new List<string>() { "ItemGrapes", "ItemSugar" };
   openRequest.OfferedInventoryInstanceIds = new List<string>() { "ItemCorn", "ItemPotato", "ItemOlive" };
   PlayFabClientAPI.OpenTrade (openRequest, OpenTradeCallback, FailCallback("OpenTrade2"));
  }

i added this error callback as you mentionned:

 

  public static ErrorCallback FailCallback(string caller)
  {
   ErrorCallback output = (PlayFabError error) =>
   {
    UnityEngine.Debug.LogError(caller + " failure: " + error.ErrorMessage);
   };
   return output;
  }

 

And the error is still the same: Invalid input parameters...

10 |1200

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

Nykos avatar image
Nykos answered

Hi, i have tried to restart another project from start and i still have the same issue. It appears i can use GetTrades, as it returns something. So i don't see why OpenTrades doesn't work at all. I have put some debug.Log at every line of the function and the OpenTrade function seem to be working, the error is triggered at the callback. Please i realy need help with that problem. It may be a dumb question, but as i said previously, i am a total newbie concerning online features, so do i need to have a server or something like this to access this function?

10 |1200

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

brendan avatar image
brendan answered

Sorry for the delay. At this point, you've tested your logic in Postman and it works, so it's just a matter of getting your sample project working, correct? Could you send us your project, so that we can have a look at it directly?

10 |1200

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

Nykos avatar image
Nykos answered

Hi, did you have the time to have a look at it?

 

10 |1200

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

brendan avatar image
brendan answered

Yes, this is a classic "if it was a snake, it would have bit me" situation. When you call OpenTrade, the items being offered need to be listed by their Item Instance IDs - a hex number representing the individual instance of the item. What you're passing in right now is the Item ID - the string representing the item in the catalog. If you update to put the Instance IDs in the call for the offered items, it should work fine.

 

Also, please be aware that our forums are public, not private. I've removed the links you posted to your project, as I'm not sure you wanted that to be publicly available for everyone to download. When sharing anything which requires privacy with us, please be sure to use the devrel@playfab.com email address. Thanks!

10 |1200

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

Nykos avatar image
Nykos answered

Hi, i think we are moving forward. Well it is still not working but the error has changed. And really thank you for all the time you spent with me. So i have the user inventory accessed and loaded, i stored the itemInstanceIds of the items i wanted traded in a file that i use for all my var storing. For now i just stored the ones that had the itemId "ItemCorn" as i wanted it simpler just to try it. My user inventory has three corn items, so i set openTrade with this function in PlayFabManager:

 

public void SetTrade()
 {
  string[] names = new string[] {DataSaver.itemInstanceIds[0], DataSaver.itemInstanceIds[1], DataSaver.itemInstanceIds[2]};
  TradeExample.OpenTrade (names);
 }

 

Then here is the OpenTrade function:

 

public static void OpenTrade(params string[] offeredInventoryInstanceIds)
  {
   var openRequest = new ClientModels.OpenTradeRequest();
   openRequest.AllowedPlayerIds = new List<string>() { PfSharedModelEx.globalClientUser.playFabId };
//   openRequest.AllowedPlayerIds = null;
   openRequest.OfferedInventoryInstanceIds = new List<string> ();
   openRequest.OfferedInventoryInstanceIds.AddRange(offeredInventoryInstanceIds);
   Debug.Log (" offered inventory instance ids : " + offeredInventoryInstanceIds[0] + "    " + offeredInventoryInstanceIds[1] + "    " + offeredInventoryInstanceIds[2]);
   openRequest.RequestedCatalogItemIds = new List<string>() { PfSharedModelEx.ItemGrapesId , PfSharedModelEx.ItemSugarId };
   Debug.Log ("requested catalog item ids : " + openRequest.RequestedCatalogItemIds[0] + "   " + openRequest.RequestedCatalogItemIds[1]);
   PlayFabClientAPI.OpenTrade(openRequest, OpenTradeCallback, PfSharedControllerEx.FailCallback("OpenTrade"));
  }

 

So now i still get an error, but it's a different one : TradeAcceptedCatalogItemInvalid.

 

As you can see in the unity console, PlayFabManager does Log in, it accesses to the catalog, and the itemInstancesIds debuged in the OpenTrade are good , as well as the itemIds for the requestedItems

 

10 |1200

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

brendan avatar image
brendan answered

Not a problem at all - working through issues in the forums provides more info for everyone, so it's always worthwhile. :)

In this case, the error means "this item doesn't appear in the catalog". Now, I know you do have those items defined - the issue is that your catalog wasn't set as the Primary Catalog for your title, which is what the trade function is checking. I've set it as the Primary now - can you re-test, and let us know if that resolved the issue?

10 |1200

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

Nykos avatar image
Nykos answered

Hey, the trade seems to open now, thanks a lot for that. But there is a new error ( yes i know...).

So, i think that this error is from OpenTradeCallback, as it displays the openTrade message with its TradeId, and the error appears just after that. I think that the next line ( PfShareModelEx.globalClientUser.RemoveItems...) is working because the items were removed from my inventory and i had to grant more to test again. What could it be?

10 |1200

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

brendan avatar image
brendan answered

Looking at the callstack, the error - a null reference - occurs in OpenTradeCallback. Can you put a breakpoint in there, and check the values being used? I'm assuming you're using the sample code from the SDK, which is updating the globalClientUser info, yes?

10 |1200

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

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.