Search code examples
c#unity-game-enginexamarinmonogame

How can I convert this Unity code to MonoGame code?


I don't know how to use PlayFab in a MonoGame project. I have read some PlayFab tutorials, but they are all for Unity and I think that it's not possible to use the Unity code samples with MonoGame, because I always get error messages.

From this line of code.

PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest(), OnGetUserInventoryRequest, OnPlayFabInventoryError);

I get the error messages here:

Error CS1503: Argument 2: cannot convert from 'method group' to 'object'

Error CS1503: Argument 3: cannot convert from 'method group' to 'Dictionary'

Something is wrong with "OnGetUserInventoryRequest, OnPlayFabInventoryError", but I don't know what I could change.

What can I change so that this code works with MonoGame?

enter image description here

https://api.playfab.com/documentation/client/method/GetUserInventory

Sample Code

public void GetInventoryList()
{
    PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest(), OnGetUserInventoryRequest, OnPlayFabInventoryError);
}
public void OnGetUserInventoryRequest(GetUserInventoryResult result)
{
    Console.WriteLine(result.VirtualCurrency);
}

public void OnPlayFabInventoryError(PlayFabError result)
{
    Console.WriteLine("Error");
}

EDIT:

I get a new error message if I want to use the value of VirtualCurrency. I don't know how to get the value of VirtualCurrency, what am I doing wrong?

private async Task GetInventoryList()
{
    var result = await PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest());

    int CurrentAmount = result.Result.VirtualCurrency;
}

Error CS0029: Cannot implicitly convert type 'System.Collections.Generic.Dictionary' to 'int'

enter image description here


Solution

  • it's pretty obvious if you look at the method signature:

    GetUserInventoryAsync(GetUserInventoryRequest request, object customData = null, Dictionary<string,string> extraHeaders = null)
    

    the last 2 parameters are optional, and they are not callback methods