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

The OpenTrade call takes three things:

  • OfferedInventoryInstanceIds: The items being offered for trade (optional - if nothing's here, you're asking for a gift).
  • RequestedCatalogItemIds: The items being asked for in trade (optional - if nothing's here, you're offering a gift).
  • RequestedCatalogItemIds: The PlayFab IDs for users allowed to accept the trade (optional - if nothing's here, anyone can accept it).

Can you provide the details for the parameters you're passing into the call?

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, thanks for the answer, but that's what i have read from the docs.

Here's my call:

TradeExample.OpenTrade("ItemCorn", "ItemWhat", null);

It's my first time using trades, so for now i'm just trying to trade corn with wheat, and i set it to null as i want every player to be able to see it. I'm almsot sure that i am not writing this the right way so could you show me the way please?

Unity doesn't show any error in the editor, but during runtime , and when this is called, it displays this error message:

OpenTrade failure: Invalid input parameters
UnityEngine.Debug:LogError(Object)
PlayFab.Examples.<FailCallback>c__AnonStorey9:<>m__0(PlayFabError) (at Assets/PlayFabSDK/Examples/API/PfSharedControllerEx.cs:76)
PlayFab.Internal.ResultContainer`1:HandleResults(CallRequestContainer, Delegate, ErrorCallback, Action`2) (at Assets/PlayFabSDK/Internal/ResultContainer.cs:86)
PlayFab.<OpenTrade>c__AnonStoreyDE:<>m__FC(CallRequestContainer) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:1860)
PlayFab.CallRequestContainer:InvokeCallback() (at Assets/PlayFabSDK/Public/PlayFabErrors.cs:250)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator0:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:252)

 

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

Thanks, that's helpful. The input parameters are all arrays of strings, rather than simple strings, so if you create arrays and add those strings to them, you should be able to call the API no problem.

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

I just tried it. Still doesn't work. I'm having the same error:

OpenTrade failure: Invalid input parameters
UnityEngine.Debug:LogError(Object)
PlayFab.Examples.<FailCallback>c__AnonStorey9:<>m__0(PlayFabError) (at Assets/PlayFabSDK/Examples/API/PfSharedControllerEx.cs:76)
PlayFab.Internal.ResultContainer`1:HandleResults(CallRequestContainer, Delegate, ErrorCallback, Action`2) (at Assets/PlayFabSDK/Internal/ResultContainer.cs:86)
PlayFab.<OpenTrade>c__AnonStoreyDE:<>m__FC(CallRequestContainer) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:1860)
PlayFab.CallRequestContainer:InvokeCallback() (at Assets/PlayFabSDK/Public/PlayFabErrors.cs:250)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator0:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:252)

Here's the code i used:

 

string[] givenTradeName = new string[1];

givenTradeName[0] = "ItemCorn";

TradeExample.OPenTrade(givenTradeName);

 

Where is the error in my code?

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

My apologies - I completely overlooked the way you were passing in the parameters. All of our API calls in that SDK use the same pattern: You create a request object, fill it out, and then pass it to the function along with your callbacks. Here's the example from the testing sample in our Unity SDK (https://github.com/PlayFab/UnitySDK/blob/56b2daf8f1d2c5bb56fda287d2cde4da6f5d4038/PlayFabCombinedTestingSample/Assets/PlayFabSDK/Examples/API/Client/TradeExample.cs):

 

public static void OpenTrade(params string[] offeredInventoryInstanceIds)
{
  var openRequest = new ClientModels.OpenTradeRequest();
  // Optional field: null is anybody, alternately if specified, this is a targeted trade request
  // In this example, we restrict the trade to ourselves (because I don't have multiple clients for this example)
  // A normal trade process would use all the same steps, but would interact between multliple clients
  openRequest.AllowedPlayerIds = new List<string>() { PfSharedModelEx.globalClientUser.playFabId };
  // Offering the items you have
  openRequest.OfferedInventoryInstanceIds = new List<string>();
  openRequest.OfferedInventoryInstanceIds.AddRange(offeredInventoryInstanceIds);
  // Listing the items you want
  openRequest.RequestedCatalogItemIds = new List<string>() { PfSharedModelEx.swillItemId };
  PlayFabClientAPI.OpenTrade(openRequest, OpenTradeCallback, PfSharedControllerEx.FailCallback("OpenTrade"));
}

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

Thanks a lot for your answer, i will try it right now and get back to you then

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

Ok,till not working, so here's what i've done:

first i have this in PlayFabManager:

 

 public void SetTrade()
 {
  string[] names = new string[] {"ItemCorn", "IemPotato", "ItemOlive"};
  TradeExample.OpenTrade (names);
 }

 

Then in TradeExample i have modified OpenTrade to integrate my variables:


  public static void OpenTrade(params string[] offeredInventoryInstanceIds)
  {
   List<string> wantedList = new List<string>(2){"ItemGrapes","ItemSugar"};
   var openRequest = new ClientModels.OpenTradeRequest();
   openRequest.AllowedPlayerIds = new List<string>() { PfSharedModelEx.globalClientUser.playFabId };
   openRequest.OfferedInventoryInstanceIds = new List<string> ();
   openRequest.OfferedInventoryInstanceIds.AddRange(offeredInventoryInstanceIds);
   // Listing the items you want
   openRequest.RequestedCatalogItemIds = new List<string>() { PfSharedModelEx.swillItemId };
   openRequest.RequestedCatalogItemIds.AddRange (wantedList);
   PlayFabClientAPI.OpenTrade(openRequest, OpenTradeCallback, PfSharedControllerEx.FailCallback("OpenTrade"));
  }

 

And i still get the same error:

 

OpenTrade failure: Invalid input parameters
UnityEngine.Debug:LogError(Object)
PlayFab.Examples.<FailCallback>c__AnonStorey9:<>m__0(PlayFabError) (at Assets/PlayFabSDK/Examples/API/PfSharedControllerEx.cs:76)
PlayFab.Internal.ResultContainer`1:HandleResults(CallRequestContainer, Delegate, ErrorCallback, Action`2) (at Assets/PlayFabSDK/Internal/ResultContainer.cs:86)
PlayFab.<OpenTrade>c__AnonStoreyDE:<>m__FC(CallRequestContainer) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:1860)
PlayFab.CallRequestContainer:InvokeCallback() (at Assets/PlayFabSDK/Public/PlayFabErrors.cs:250)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator0:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:252)

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

Can you check in the debugger to see what the specific values are that you've set in the request? For example, did you actually add the Swill item to your own catalog and use the sample code to retrieve it? Also, have you defined the callbacks in question, or are you using the test code?

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

I am using the test code: TradeExample

Ok so, now i see the error with the swill item ( didn't( figure out it WAS an item). i removed it and replaced it by my list of requestedItems. Here's the updated code:

 

  public static void OpenTrade(params string[] offeredInventoryInstanceIds)
  {
   List<string> wantedList = new List<string>(2){"ItemGrapes","ItemSugar"};
   var openRequest = new ClientModels.OpenTradeRequest();
   openRequest.AllowedPlayerIds = new List<string>() { PfSharedModelEx.globalClientUser.playFabId };
   openRequest.OfferedInventoryInstanceIds = new List<string> ();
   openRequest.OfferedInventoryInstanceIds.AddRange(offeredInventoryInstanceIds);
   // Listing the items you want
   openRequest.RequestedCatalogItemIds = wantedList;
   Debug.Log ("" + openRequest.OfferedInventoryInstanceIds[0] + openRequest.OfferedInventoryInstanceIds[1] + openRequest.OfferedInventoryInstanceIds[2]);
//   openRequest.RequestedCatalogItemIds.AddRange (wantedList);
   PlayFabClientAPI.OpenTrade(openRequest, OpenTradeCallback, PfSharedControllerEx.FailCallback("OpenTrade"));
  }

Of course it hasn't changed a thing. All the other items i am using are added to my catalog and set as tradable. And i also added them to my inventory ( directly granted in the manager).

From what i read, you seem to be saying that items have to be retrieved first? What do you mean? Do i have to load the catalog in the TradeExample script?

Do items have to be set in PFShareedModelEx like the SwillItem was?

And thanks again for your help.

 

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

I added every needed items in PfSharedModelEx, name and id variables, just like SwillName and SwillItemId. But it seems that in TradeExample, the "OnCatalogLoaded" and "OnUserLogin" function are never called, they are in the static TradeExample at the start of the script. So i think that the items are never retrieved.

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.